new stream.Transform([options])
options
<Object> 传给Writable
和Readable
构造函数。 还具有以下字段:transform
<Function>stream._transform()
方法的实现。flush
<Function>stream._flush()
方法的实现。
const { Transform } = require('stream');
class MyTransform extends Transform {
constructor(options) {
super(options);
// ...
}
}
或者,当使用 ES6 之前的风格构造函数时:
const { Transform } = require('stream');
const util = require('util');
function MyTransform(options) {
if (!(this instanceof MyTransform))
return new MyTransform(options);
Transform.call(this, options);
}
util.inherits(MyTransform, Transform);
或者,使用简化的构造函数方法:
const { Transform } = require('stream');
const myTransform = new Transform({
transform(chunk, encoding, callback) {
// ...
}
});
options
<Object> Passed to bothWritable
andReadable
constructors. Also has the following fields:transform
<Function> Implementation for thestream._transform()
method.flush
<Function> Implementation for thestream._flush()
method.
const { Transform } = require('stream');
class MyTransform extends Transform {
constructor(options) {
super(options);
// ...
}
}
Or, when using pre-ES6 style constructors:
const { Transform } = require('stream');
const util = require('util');
function MyTransform(options) {
if (!(this instanceof MyTransform))
return new MyTransform(options);
Transform.call(this, options);
}
util.inherits(MyTransform, Transform);
Or, using the simplified constructor approach:
const { Transform } = require('stream');
const myTransform = new Transform({
transform(chunk, encoding, callback) {
// ...
}
});