Exclude streamifier dependancy

dev
Roman Burunkov 5 years ago committed by GitHub
parent f8c078df0d
commit bb22dec4c5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 18
      lib/utilities.js

@ -2,8 +2,7 @@
const fs = require('fs');
const path = require('path');
const streamifier = require('streamifier');
const Readable = require('stream').Readable;
/**
* Returns true if argument is function.
@ -50,7 +49,7 @@ const copyFile = function(src, dst, callback){
runCb(err);
});
writable.on('close', () => runCb());
//Copieng file via piping streams.
//Copy file via piping streams.
readable.pipe(writable);
};
@ -64,10 +63,19 @@ const saveBufferToFile = function(buffer, filePath, callback){
callback(new Error('buffer variable should be a Buffer!'));
return;
}
const fstream = fs.createWriteStream(filePath);
streamifier.createReadStream(buffer).pipe(fstream);
//Setup readable stream from buffer.
let streamData = buffer;
let readStream = Readable();
readStream._read = ()=>{
readStream.push(streamData);
streamData = null;
};
//Setup file system writable stream.
let fstream = fs.createWriteStream(filePath);
fstream.on('error', error => callback(error));
fstream.on('close', () => callback());
//Copy file via piping streams.
readStream.pipe(fstream);
};
module.exports = {

Loading…
Cancel
Save