jimmywarting / StreamSaver.js

StreamSaver writes stream to the filesystem directly asynchronous
https://jimmywarting.github.io/StreamSaver.js/example.html
MIT License
3.95k stars 413 forks source link

The browser will crash when downloading files exceeding 2G through fetch #336

Closed SakuraYou closed 7 months ago

SakuraYou commented 7 months ago
  $start.onclick = () => {
    const url = 'xxxx', // a 2gb size file
    const fileStream = streamSaver.createWriteStream('cat.mp4')

    fetch(url).then(res => {
      const readableStream = res.body

      // more optimized
      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()
    })
  }
jimmywarting commented 7 months ago

Browser?

SakuraYou commented 7 months ago

Browser?

yes!

jimmywarting commented 7 months ago

I mean... what browser & version are you using to cause a crash?

SakuraYou commented 7 months ago

Sorry, it’s my problem. A colleague here rewrote the fetch method, causing memory accumulation.