nntp-fast
Version:
A lightweight nntp client for node made with attention to speed and ease of use. Works with promises and streams.
53 lines (52 loc) • 1.87 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 (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var stream_1 = require("stream");
var StreamSearch = require("streamsearch");
var CRLF = Buffer.from("\r\n");
/**
* Transform stream that performs dot-unstuffing
*/
var DotUnstuffingStream = /** @class */ (function (_super) {
__extends(DotUnstuffingStream, _super);
function DotUnstuffingStream() {
var _this = _super.call(this) || this;
_this._streamsearch = new StreamSearch(Buffer.from("\r\n."));
_this._streamsearch.on("info", function (isMatch, data, start, end) {
if (data) {
if (start == 0 && end == data.length) {
_this.push(data);
}
else {
_this.push(data.slice(start, end));
}
}
if (isMatch) {
_this.push(CRLF);
}
});
return _this;
}
/**
*
* @private
*/
DotUnstuffingStream.prototype._transform = function (chunk, encoding, callback) {
this._streamsearch.push(chunk);
callback();
};
return DotUnstuffingStream;
}(stream_1.Transform));
exports.default = DotUnstuffingStream;