streaming
Version:
Transforms and other streaming helpers
60 lines (59 loc) • 2.23 kB
JavaScript
;
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.Omitter = exports.Picker = void 0;
var stream_1 = require("stream");
var Picker = /** @class */ (function (_super) {
__extends(Picker, _super);
function Picker(fields) {
// objects in, objects out
var _this = _super.call(this, { objectMode: true }) || this;
_this.fields = fields;
return _this;
}
Picker.prototype._transform = function (chunk, encoding, callback) {
var filtered = {};
for (var i = 0; i < this.fields.length; i++) {
filtered[this.fields[i]] = chunk[this.fields[i]];
}
this.push(filtered, encoding);
callback();
};
return Picker;
}(stream_1.Transform));
exports.Picker = Picker;
var Omitter = /** @class */ (function (_super) {
__extends(Omitter, _super);
function Omitter(fields) {
// objects in, objects out
var _this = _super.call(this, { objectMode: true }) || this;
_this.fieldsMap = {};
for (var i = 0, l = fields.length; i < l; i++) {
_this.fieldsMap[fields[i]] = 1;
}
return _this;
}
Omitter.prototype._transform = function (chunk, encoding, callback) {
for (var field in this.fieldsMap) {
delete chunk[field];
}
this.push(chunk, encoding);
callback();
};
return Omitter;
}(stream_1.Transform));
exports.Omitter = Omitter;