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

Incomplete download when write to the streamSaver #339

Open
Zhangjiawei-Beinloft opened this issue Mar 12, 2024 · 1 comment
Open

Incomplete download when write to the streamSaver #339

Zhangjiawei-Beinloft opened this issue Mar 12, 2024 · 1 comment

Comments

@Zhangjiawei-Beinloft
Copy link

Zhangjiawei-Beinloft commented Mar 12, 2024

I follow the example of "Piping a fetch response to StreamSaver". When I download small file like 1KB, the code below works and it can console log the message "done writing". But I download bigger file like 57.7KB, readableStream.pipeTo(fileStream) never finish and the http request is not finished all the time.

I'm not sure if the write operation is blocking the reception of the data stream?Or is it something else?

The code:

fetch(url).then(res => {
          const readableStream = res.body
          if (window.WritableStream && readableStream.pipeTo) {
            return readableStream.pipeTo(fileStream)
              .then(() => console.log('done writing'))
          }
          window.writer = fileStream.getWriter()
          const reader = res.body.getReader()
          const pump = () => reader.read()
            .then(res => res.done
              ? writer.close()
              : writer.write(res.value).then(pump))
          pump()
        })
@Zhangjiawei-Beinloft
Copy link
Author

微信图片_20240313094630

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant