@r1tsu/payload
Version:
20 lines (19 loc) • 628 B
JavaScript
import fs from 'fs';
import { Readable } from 'stream';
/**
* Save buffer data to a file.
* @param {Buffer} buffer - buffer to save to a file.
* @param {string} filePath - path to a file.
*/ const saveBufferToFile = async (buffer, filePath)=>{
// Setup readable stream from buffer.
let streamData = buffer;
const readStream = new Readable();
readStream._read = ()=>{
readStream.push(streamData);
streamData = null;
};
// Setup file system writable stream.
return fs.writeFileSync(filePath, buffer);
};
export default saveBufferToFile;
//# sourceMappingURL=saveBufferToFile.js.map