6

There are several solutions for saving a data blob to a file in a browser environment. I normally use FileSaver.js.

In this particular case, though, my data comes in from a websocket stream, and the resulting file might be so large (hundreds of MB) that concatenating it in memory really kills performance.


Is it at all possible to open a stream that data can be written to as it comes in?


Edit:

The websocket is an XMPP connection. The file transfer is negotiated via Stream Initiation (XEP-0095) using the SI File Transfer (XEP-0096) protocol; the data is then transferred via an In Band Bytestream (XEP-0047).

Basically, the web application gets the data in base64-encoded chunks of 4096 bytes, and I'd like to know if there is any way to let the user save the file before all the data is received.

Sach
  • 10,091
  • 8
  • 47
  • 84
Christoph Burschka
  • 4,467
  • 3
  • 16
  • 31
  • 6
    Your question could use a lot more context. For instance, by following the link (which I shouldn't have to do), I can see the FileSaver.js seems to be targeted at client-side code running in web browsers. Is that your target environment? And where is the stream coming from? – T.J. Crowder Jan 01 '16 at 15:47
  • 2
    If you're receiving the file block by block via the web socket, can't you just hand each block over to the file system? – Pointy Jan 01 '16 at 15:58
  • Instead of using websockets you could re-configure your server to send a file. – Rodrigo5244 Jul 16 '16 at 17:37
  • If you know how to concatenate them in memory, you can do the same in files with filesystem api. Take a look how mega use filesystem to download large file with filesystem api: http://stackoverflow.com/questions/15994554/download-files-like-mega-co-nz – Mark Ni Apr 21 '17 at 00:38

0 Answers0