Save stream from socket.io stream package to the file #279
-
In the browser I'm requesting pretty large binary file (~1 Gb) from a server through socket.io stream. It's being streamed by chunks. Is it possible to save it to the file directly not via saving to Blob first? I've tried it this way and in it didn't work. const socketStream = reqiure('socket.io-stream')
const fileStream = streamSaver.createWriteStream('filename.zip')
const targetStream = socketStream.createsStream() // Readable-writable stream
socketStream(socket).emit('get-large-file', targetStream)
targetStream.pipe(fileStream) Maybe I'm missing something? Thank you. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
If you have the possibility to save the file using nothing but the server then that would be my recommendation for solving things instead of using streamsaver to emulate what a server dose using service worker to get around the problem. streamsaver and other alike is mostly build for site that generates huge data on the client side (like a webcam recording) anyhow... it looks like the stream is a NodeJS stream and not a whatwg (web) stream so so i bet u would have to read the stream and write manually to the StreamSaver const stream = streamSaver.createWriteStream('filename.zip')
const writer = stream.getWriter()
writer.write(new Uint8Array(data)) |
Beta Was this translation helpful? Give feedback.
If you have the possibility to save the file using nothing but the server then that would be my recommendation for solving things instead of using streamsaver to emulate what a server dose using service worker to get around the problem. streamsaver and other alike is mostly build for site that generates huge data on the client side (like a webcam recording)
anyhow... it looks like the stream is a NodeJS stream and not a whatwg (web) stream so
.pipe()
don't work together web streams uses pipeToso i bet u would have to read the stream and write manually to the StreamSaver