UNPKG

payload

Version:

Node, React, Headless CMS and Application Framework built on Next.js

19 lines (18 loc) 613 B
import fs from 'fs/promises'; 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. */ export 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 await fs.writeFile(filePath, buffer); }; //# sourceMappingURL=saveBufferToFile.js.map