Last active
January 10, 2021 00:04
-
-
Save redoPop/41e98226ebb0761b0d01de5186dbc7a4 to your computer and use it in GitHub Desktop.
Simple file streamer for Deno.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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