stream.push()

stream.push('')

Pushing a zero-byte string or Buffer (when not in Object mode) has an interesting side effect. Because it is a call to stream.push(), it will end the reading process. However, it does not add any data to the readable buffer, so there's nothing for a user to consume.

Very rarely, there are cases where you have no data to provide now, but the consumer of your stream (or, perhaps, another bit of your own code) will know when to check again, by calling stream.read(0). In those cases, you may call stream.push('').

So far, the only use case for this functionality is in the tls.CryptoStream class, which is deprecated in Node.js/io.js v1.0. If you find that you have to use stream.push(''), please consider another approach, because it almost certainly indicates that something is horribly wrong.

doc_Nodejs
2016-04-30 04:42:24
Comments
Leave a Comment

Please login to continue.