Skip to content

Instantly share code, notes, and snippets.

@redoPop
Last active January 10, 2021 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save redoPop/41e98226ebb0761b0d01de5186dbc7a4 to your computer and use it in GitHub Desktop.
Save redoPop/41e98226ebb0761b0d01de5186dbc7a4 to your computer and use it in GitHub Desktop.
Simple file streamer for Deno.
function streamFile(path: string) {
let file: Deno.File,
iter: AsyncIterableIterator<Uint8Array>;
return new ReadableStream({
async start() {
file = await Deno.open(path);
iter = Deno.iter(file);
},
async pull(controller) {
const { value: chunk, done } = await iter.next();
if (done) controller.close();
else controller.enqueue(chunk);
},
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment