stream: fix regression on duplex end
Decide the return status of writeOrBuffer before calling stream.write which can reset state.length
Fixes: https://github.com/nodejs/node/issues/35926
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines