Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
19 lines
613 B
Plaintext
19 lines
613 B
Plaintext
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 |