UNPKG

streaming

Version:

Transforms and other streaming helpers

47 lines (42 loc) 1.77 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Transformer = void 0; var stream_1 = require("stream"); /** Like Mapper, but more bare-bones. The predicate function has to call a given callback, which means the processing code can be async. `this` is bound to the stream object inside the transform function, so you can use `this.push(...)` to output multiple chunks per single input chunk. Example: new streaming.Transformer(function(chunk, encoding, callback) { setTimeout(() => { this.push('...'); this.push(chunk); callback(); }, 1000); }, {objectMode: true}); */ var Transformer = /** @class */ (function (_super) { __extends(Transformer, _super); function Transformer(transformFn, options) { var _this = _super.call(this, options) || this; _this._transform = transformFn.bind(_this); return _this; } return Transformer; }(stream_1.Transform)); exports.Transformer = Transformer;