Are the following two meanings the same?
Is stream.pipe (…) the same thing as stream itself?
But when Object.is(stream,stream.pipe (…) returns
Is that what they mean?
Only a readable stream can have a pipe method to call. The pipe method receives a writable stream object as the target of pipe
It is to establish a channel between a readable stream and a writable stream, write the data in Readable into destination, and return the stream object specified by destination after pipe is executed.
The return of stream.pipe (…) is not the same object as stream.
The same stream is written to the specified writable stream destinationA/destinationB through pipe.
Stream stream writes to destinationA if
stream.pipe(destinationA)The returned stream is also readable, then the pipe method can be called in chain to write the stream to destinationB
A prerequisite for pipe method to be able to be called in chain is that the stream returned by pipe is readable.
var r = fs.createReadStream('file.txt'); var z = zlib.createGzip(); var w = fs.createWriteStream('file.txt.gz'); r.pipe(z).pipe(w);
The zlib data stream is both a writable stream and a readable stream.