- Version: v6.3.1
- Platform: all
- Subsystem: Duplex, Docs
This is the code snippet of code example of Duplex Stream in Docs.
_write(chunk, encoding, callback) {
// The underlying source only deals with strings
if (Buffer.isBuffer(chunk))
chunk = chunk.toString(encoding);
this[kSource].writeSomeData(chunk, encoding);
callback();
}
If incoming chunk is an instance of Buffer, then encoding argument is supposed to be 'buffer' rather than String encoding types. So in this example, 'buffer' is passed as encoding into toString() and writeSomeData() methods instead of desired string encoding.