Answer the question
In order to leave comments, you need to log in
How to make a Transform Stream?
Hey Ya!
There is a task, to file a class for loading a file (nodejs) must be able to write and read the file.
Theory:
var utils = require('utils');
var TransformStream = require('stream').TransformStream;
function WriteReadStream(path, options) {
TransformStream.call(this);
}
WriteReadStream.prototype._transform = function(chunk, encoding, cb) {
// что то нужно сделать здесь
};
utils.inherit(WriteReadStream, TransformStream);
var file = new WriteReadStream('/tmp/file');
req.pipe(file);
var file = new WriteReadStream('/tmp/file');
file.pipe(res);
Answer the question
In order to leave comments, you need to log in
Do not inherit from there, see the example in the source code of the node in /lib/crypto.js
For example, the Hash class is written like this, it inherits LazyTransform, like this: util.inherits(Hash, LazyTransform); then LazyTransform inherits from stream.Transform like this: util.inherits(LazyTransform, stream.Transform); and then the _transform method is defined
Hash.prototype._transform = function(chunk, encoding, callback) {
this._binding.update(chunk, encoding);
callback();
};
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question