mirror of
https://github.com/nodejs/node.git
synced 2026-11-09 15:11:11 -05:00
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 <fedor@indutny.com>
This commit is contained in:
1 parent
542ac7f3d2
commit
c8e0bdd7cf
1 file changed
+15
-2
+15
-2
@@ -1071,7 +1071,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
|
||||
@@ -1091,7 +1091,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
|
||||
|
||||
Reference in new issue
Block a user