本文整理汇总了TypeScript中gridfs-stream.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了default函数的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: function
fs.open (filepath, 'r', function (err, fd) {
if (!err) {
// File already exits
fs.closeSync (fd);
resolve (null);
}
else {
// File does not exist...create it
var fs_write_stream = fs.createWriteStream (filepath);
var gfs = Grid(conn.db);
//read from mongodb
var readstream = gfs.createReadStream ({_id: file._id});
readstream.pipe (fs_write_stream);
fs_write_stream.on ('close', function () {
console.log ('file created: ' + filepath);
resolve (null);
});
fs_write_stream.on ('error', function () {
err = 'file creation error: ' + filepath;
reject (err);
});
}
});
示例2: Grid
collection.findOne({filename: request.params.name}, (error:any, item:any):void => {
if (!error) {
if (item) {
var gfs = Grid(conn.db, mongoose.mongo); //missing parameter
if (gfs) {
var readstream = gfs.createReadStream({filename: request.params.name});
if (readstream) {
readstream.pipe(response);
readstream.on('close', (file:any):void => {
conn.db.close();
logger.trace("end /file/:name");
});
} else {
conn.db.close();
logger.error("/file/:name 1");
next();
}
} else {
conn.db.close();
logger.error("/file/:name 2");
next();
}
} else {
conn.db.close();
logger.error("/file/:name 3");
next();
}
} else {
conn.db.close();
logger.error("/file/:name 4");
next();
}
});
示例3: Promise
return new Promise (function (resolve, reject) {
var gfs = Grid(conn.db);
gfs.remove ({_id : file._id}, function (err) {
err ? reject (err) : resolve (null);
});
});
示例4: Promise
new Promise((resolve, reject) => {
const gfs = Grid(conn.db);
const writestream = gfs.createWriteStream({
_id: new ObjectID(),
filename: filename,
metadata: { collection_id: collection_id, category: category }
});
fs.createReadStream(filepath).pipe(writestream);
writestream.on('close', (file: any) => resolve(null));
});