UNPKG

debian-control

Version:

Parse package control files from Debian

78 lines (65 loc) 2.36 kB
// Generated by CoffeeScript 2.4.1 (function() { // paragraphStream.coffee // Copyright 2019 Patrick Meade. // This program is free software: you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by // the Free Software Foundation, either version 3 of the License, or // (at your option) any later version. // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // You should have received a copy of the GNU General Public License // along with this program. If not, see <https://www.gnu.org/licenses/>. //---------------------------------------------------------------------- var LINE_MIDDLE, LINE_START, Transform; ({Transform} = require("stream")); LINE_START = "LINE_START"; LINE_MIDDLE = "LINE_MIDDLE"; exports.ParagraphStream = class ParagraphStream extends Transform { constructor(options) { super(options || {}); this.linebuffer = ""; this.parabuffer = []; this.state = LINE_START; } _transform(chunk, encoding, callback) { var c, chunkstr, i, len; chunkstr = chunk.toString(); for (i = 0, len = chunkstr.length; i < len; i++) { c = chunkstr[i]; if (this.state === LINE_START) { if (c === "\n") { if (this.parabuffer.length > 0) { this.push(this.parabuffer.join("")); this.parabuffer = []; } } else { this.state = LINE_MIDDLE; this.linebuffer += c; } } else { this.linebuffer += c; if (c === "\n") { this.parabuffer.push(this.linebuffer); this.linebuffer = ""; this.state = LINE_START; } } } return callback(); } _flush(callback) { if (this.linebuffer.length > 0) { this.parabuffer.push(this.linebuffer); } if (this.parabuffer.length > 0) { this.push(this.parabuffer.join("")); } return callback(); } }; //---------------------------------------------------------------------- // end of paragraphStream.coffee }).call(this);