• options {Object} 同时传给 WritableReadable 的构造函数。
      • transform {Function} 对 [stream._transform()][stream-_transform] 的实现。
      • flush {Function} 对 [stream._flush()][stream-_flush] 的实现。
    1. const { Transform } = require('stream');
    2. class MyTransform extends Transform {
    3. constructor(options) {
    4. super(options);
    5. // ...
    6. }
    7. }

    使用 ES6 之前的语法:

    1. const { Transform } = require('stream');
    2. const util = require('util');
    3. function MyTransform(options) {
    4. if (!(this instanceof MyTransform))
    5. return new MyTransform(options);
    6. Transform.call(this, options);
    7. }
    8. util.inherits(MyTransform, Transform);

    使用简化的构造函数:

    1. const { Transform } = require('stream');
    2. const myTransform = new Transform({
    3. transform(chunk, encoding, callback) {
    4. // ...
    5. }
    6. });