streams: non-writable Duplex is writable (more annoyance than bug)
@mcollina @ronag @nodejs/streams
const { Duplex } = require('stream'); const d = new Duplex({ writable: false, write(chunk, encoding, cb) { console.log(chunk.toString()); cb(); } }); console.log(d.writable); // false! as expected... d.write('darn it'); // prints, 'darn it' and returns true
This isn't a bug since it's been like this forever but the behavior is really counter intuitive, especially since after calling d.end() and then doing a d.write() we get a proper write after end error. It makes implementing a custom Duplex (e.g. QuicStream) more difficult because of the additional checks that need to be made to ensure that even tho the Duplex isn't writable no-one is writing to it.
Not sure what the fix is immediately but wanted to discuss it first.
The ideal behavior, I would think, is an error similar to write after end if write() is called on a non-writable Duplex.