Description
- Version: v10.0.0
- Platform:Darwin tmcw.local 17.5.0 Darwin Kernel Version 17.5.0: Fri Apr 13 19:32:32 PDT 2018; root:xnu-4570.51.2~1/RELEASE_X86_64 x86_64
- Subsystem: stream
Hi Maintainers!
This may be the same underlying issue as #20503 - I'm not confident enough in the node core space enough to tell.
This problem was first noticed in cp-file, a dependency of cpy, which is a dependency of one of my projects. A very distilled test case is:
const fs = require('fs');
const read = fs.createReadStream(__filename);
read.on('readable', () => {
read.on('data', chunk => {
console.log('data');
});
});
This is a program that reads itself, by creating a read stream, waiting for it to be readable, and then assigning a data event listener. It prints data
on all node versions < 10, but prints nothing on the Node v10.0.0 release.
In situ, cp-file tries to ensure that a stream is readable before creating the destination directory and then calling .pipe
to write the file to disk. As far as I can tell, Node v10 changes the behavior of readable streams such that data events are not emitted if you bind the data event listener after readable is emitted.