Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support passing ReadableStream to Deno.writeFile #13229

Closed
lucacasonato opened this issue Dec 29, 2021 · 4 comments · Fixed by #17329
Closed

Support passing ReadableStream to Deno.writeFile #13229

lucacasonato opened this issue Dec 29, 2021 · 4 comments · Fixed by #17329
Labels
help wanted community help requested public API related to "Deno" namespace in JS suggestion suggestions for new features (yet to be agreed)

Comments

@lucacasonato
Copy link
Member

This would make streaming data to disk really easy. writeFile cancellations should be propagated into the readable stream reading. Only ReadableStream<Uint8Array> would be allowed. writeTextFile would allow ReadableStream<string>.

This would be in addition to allowing Uint8Array / string as we do now.

@lucacasonato lucacasonato added public API related to "Deno" namespace in JS suggestion suggestions for new features (yet to be agreed) labels Dec 29, 2021
@duncanmak
Copy link

Maybe this can be closed? See #13614.

@irustm
Copy link

irustm commented Jan 6, 2023

It would be nice, since right now the file upload goes something like this:

import { readAll, readerFromStreamReader } from "https://deno.land/std@0.171.0/streams/conversion.ts";

//// body: FormData
const firstFile = body.get('file');

if (firstFile instanceof File) {
      const fileDest = firstFile.name;

      // write the file if the file has content in memory
      if (firstFile.size) {
        const reader = firstFile.stream().getReader();
        const stream = readerFromStreamReader(reader);
        const file = await readAll(stream);

        await Deno.writeFile(fileDest, file, { append: true });
      }
}

@bartlomieju bartlomieju added the help wanted community help requested label Jan 6, 2023
@bartlomieju
Copy link
Member

This is reasonable and we should implement this. PRs are very welcome!

@wwoast
Copy link

wwoast commented Feb 23, 2024

#19697 tracks a bug in the passing of ReadableStream to Deno.writeFile. I uncovered the same bug last night when I was looking for ways to get rid of my use of streams/copy, prior to discovering the newer io/copy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted community help requested public API related to "Deno" namespace in JS suggestion suggestions for new features (yet to be agreed)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants