From 90f07a7b3ebb779832ab01204d994e4feab850d1 Mon Sep 17 00:00:00 2001 From: Calvin Metcalf Date: Wed, 3 Sep 2014 09:01:15 -0400 Subject: [PATCH] doc: document _transform callback takes 2 args Expands the paragraph in the transform stream implementation docs about the callback that is passed to the _transform method to include details about how two arguments may be passed, error and data. A code example is also included. Reviewed-by: Fedor Indutny Cherry-picked-from: https://github.com/joyent/node/commit/c8e0bdd7cf628ee2f3f79e5538132467bbc50b4a --- doc/api/stream.markdown | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/doc/api/stream.markdown b/doc/api/stream.markdown index d1fa2cca35..1029c43c94 100644 --- a/doc/api/stream.markdown +++ b/doc/api/stream.markdown @@ -1155,7 +1155,7 @@ initialized. * `encoding` {String} If the chunk is a string, then this is the encoding type. (Ignore if `decodeStrings` chunk is a buffer.) * `callback` {Function} Call this function (optionally with an error - argument) when you are done processing the supplied chunk. + argument and data) when you are done processing the supplied chunk. Note: **This function MUST NOT be called directly.** It should be implemented by child classes, and called by the internal Transform @@ -1175,7 +1175,20 @@ as a result of this chunk. Call the callback function only when the current chunk is completely consumed. Note that there may or may not be output as a result of any -particular input chunk. +particular input chunk. If you supply as the second argument to the +it will be passed to push method, in other words the following are +equivalent: + +```javascript +transform.prototype._transform = function (data, encoding, callback) { + this.push(data); + callback(); +} + +transform.prototype._transform = function (data, encoding, callback) { + callback(null, data); +} +``` This method is prefixed with an underscore because it is internal to the class that defines it, and should not be called directly by user