I'm building a file upload application to familiarize myself with the concept of streams. I'm trying to turn a file list or blobs into a stream then upload it to the backend and store it on the file system.
I had no issue with frontend and backend implementations respectively but I'm having a hard time connecting the two. My main problem is that I don't understand the difference between the Web Streams API and the Node.js Streams API. I managed to turn the blobs of selected input files in the browser into a Web ReadableStream
but the packages I tried (axios
for requests, socket.io
and socket.io-stream
for WebSocket) only accept the Node.js version Stream as arguments. I also could not pipe a Web ReadableStream into a Node.js Writeable or Duplex Stream. The method names are also different (e.g.: pipeTo
or pipeThrough
in Web API and pipe
in Node.js API).
I know there are implementation differences between Node.js and browsers but naively, I thought the APIs would be similar. Can I somehow trivially convert between Web streams and browserified Node.js streams and I'm missing something? Does it worth using the Web Stream API over stream-browserify
?
axios
probably has just confusing types, their browser API allows onlyFormData
,File
, andBlob
, in addition to the common ones likestring
,ArrayBuffer
, etc. Their server API hasStream
andBuffer
though, so I thought I can use this on the frontend too. I can't remember why I couldn't makesocket.io
work, you're right that I should have added sample code. – Berl