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
25 lines
724 B
Plaintext
25 lines
724 B
Plaintext
import fs from 'fs';
|
|
export function iteratorToStream(iterator) {
|
|
return new ReadableStream({
|
|
async pull (controller) {
|
|
const { done, value } = await iterator.next();
|
|
if (done) {
|
|
controller.close();
|
|
} else {
|
|
controller.enqueue(value);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
export async function* nodeStreamToIterator(stream) {
|
|
for await (const chunk of stream){
|
|
yield new Uint8Array(chunk);
|
|
}
|
|
}
|
|
export function streamFile({ filePath, options }) {
|
|
const nodeStream = fs.createReadStream(filePath, options);
|
|
const data = iteratorToStream(nodeStreamToIterator(nodeStream));
|
|
return data;
|
|
}
|
|
|
|
//# sourceMappingURL=index.js.map |