You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
node:internal/webstreams/readablestream:2280
throw new ERR_INVALID_ARG_VALUE('stream', stream, 'must be a byte stream');
^
TypeError [ERR_INVALID_ARG_VALUE]: The argument 'stream' must be a byte stream. Received ReadableStream { locked: false, state: 'readable', supportsBYOB: false }
at setupReadableStreamBYOBReader (node:internal/webstreams/readablestream:2280:11)
at new ReadableStreamBYOBReader (node:internal/webstreams/readablestream:935:5)
at ReadableStream.getReader (node:internal/webstreams/readablestream:346:12)
at Socket.<anonymous> (file:///home/hansklunder/github/opifex/tmp.js:6:29)
at Object.onceWrapper (node:events:632:28)
at Socket.emit (node:events:518:28)
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:10) {
code: 'ERR_INVALID_ARG_VALUE'
}
Which makes sense in its current implementation.
Solving this would bring better compatibility with the WinterCG standards and would make it easier to implement TCP bytestream protocols in NodeJS.
What is the feature you are proposing to solve the problem?
It would be nice if I could signal either at the creation of the socket or the Readable.toWeb() that I want a ReadableByteStream instead of ReadableDefaultStream.
Even more brilliant would be if I could skip the Readable.toWeb() call also somehow, e.g. by importing node:sockets or something similar.
What alternatives have you considered?
I've currently hacked my own layer on top of the socket event API:
import{Writable}from"node:stream";functioncloser(sock){if(!sock.closed){sock.end();}}exportfunctionwrapNodeSocket(socket){constreadable=newReadableStream({type: "bytes",start(controller){socket.on("data",(data)=>{controller.enqueue(data);constdesiredSize=controller.desiredSize??0;if(desiredSize<=0){// The internal queue is full, so propagate// the backpressure signal to the underlying source.socket.pause();}});socket.on("error",(err)=>controller.error(err));socket.on("end",()=>{// close the controllercontroller.close();// and unlock the last BYOB read requestcontroller.byobRequest?.respond(0);});},pull: ()=>{socket.resume();},cancel: ()=>{socket.end();},});constwritable=Writable.toWeb(socket);constremoteAddr={hostname: socket.remoteAddress||"",port: socket.remotePort||0,};constconn={readable: readable,writable: writable,close: ()=>closer(socket),
remoteAddr,};returnconn;}
This works, but it would be nice if it was part of standard NodeJS functionality.
The text was updated successfully, but these errors were encountered:
What is the problem this feature will solve?
As mentioned by the winterCG it is reasonable to assume that most TCP cases are bytes oriented. And my case (MQTT server/client) is one of them.
However:
Gives me:
Which makes sense in its current implementation.
Solving this would bring better compatibility with the WinterCG standards and would make it easier to implement TCP bytestream protocols in NodeJS.
What is the feature you are proposing to solve the problem?
It would be nice if I could signal either at the creation of the socket or the Readable.toWeb() that I want a ReadableByteStream instead of ReadableDefaultStream.
Even more brilliant would be if I could skip the
Readable.toWeb()
call also somehow, e.g. by importingnode:sockets
or something similar.What alternatives have you considered?
I've currently hacked my own layer on top of the socket event API:
This works, but it would be nice if it was part of standard NodeJS functionality.
The text was updated successfully, but these errors were encountered: