writeStream.js 463 B

12345678910111213141516171819202122
  1. 'use strict';
  2. var streamFile = require('../../src/getContents/streamFile');
  3. var fs = require('graceful-fs');
  4. function writeStream (writePath, file, cb) {
  5. var opt = {
  6. mode: file.stat.mode
  7. };
  8. var outStream = fs.createWriteStream(writePath, opt);
  9. file.contents.once('error', cb);
  10. outStream.once('error', cb);
  11. outStream.once('finish', function() {
  12. streamFile(file, cb);
  13. });
  14. file.contents.pipe(outStream);
  15. }
  16. module.exports = writeStream;