如何在Gridfs Stream中使用WriteStream

时间:2018-04-24 03:11:04

标签: node.js

gridfs-stream中的Writestream是什么?它有什么作用?另外,从写入流创建读取流所需的路径是什么

var writestream = gfs.createWriteStream({
      filename: 'my_file.txt'
});
fs.createReadStream('/some/path').pipe(writestream);

// streaming from gridfs
var readstream = gfs.createReadStream({
filename: 'my_file.txt'
});

//error handling, e.g. file does not exist
readstream.on('error', function (err) {
console.log('An error occurred!', err);
throw err;
});

readstream.pipe(response);

0 个答案:

没有答案