jimmywarting / StreamSaver.js

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

Downloading files Error code: Out of Memory #280

Open viperDel opened 2 years ago

viperDel commented 2 years ago

I tried your example code for fetch just changed a little bit to download more than one file at the time, the first file seems to be downloaded just fine but it crushes on the second one throwing error "Out of Memory" and sometimes it crushes on the first file. I even tried your example code without changes (except the url) and sometimes it crushes throwing the same error. I checked if I'm really running out of memory (on task manager) but that doesn't seem to be the case

the videos are 4.5GB in size

am I missing something?


<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Piping a fetch response to StreamSaver</title>
  </head>
  <body>
    <button id="$start">Start</button>
    <script src="https://cdn.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/ponyfill.min.js"></script>
    <script src="../StreamSaver.js"></script>
    <script>
      $start.onclick = async () => {
        var files=[];

        files.push('video.mp4');
        files.push('video2.mp4');

    for await (const fileName of files) {

        const url = 'http://localhost/'+fileName
        const fileStream = streamSaver.createWriteStream(fileName)

       await 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()
        })

    }
      }
    </script>
  </body>
</html>
OOM OOM code