Files
codeql-action/node_modules/unzip-stream/lib/parser-stream.js
Angela P Wen a196a714b8 Bump artifact dependencies if CODEQL_ACTION_ARTIFACT_V2_UPGRADE enabled (#2482)
Co-authored-by: Andrew Eisenberg <aeisenberg@github.com>
Co-authored-by: Henry Mercer <henrymercer@github.com>
2024-10-01 09:59:05 -07:00

52 lines
1.4 KiB
JavaScript

var Transform = require('stream').Transform;
var util = require('util');
var UnzipStream = require('./unzip-stream');
function ParserStream(opts) {
if (!(this instanceof ParserStream)) {
return new ParserStream(opts);
}
var transformOpts = opts || {};
Transform.call(this, { readableObjectMode: true });
this.opts = opts || {};
this.unzipStream = new UnzipStream(this.opts);
var self = this;
this.unzipStream.on('entry', function(entry) {
self.push(entry);
});
this.unzipStream.on('error', function(error) {
self.emit('error', error);
});
}
util.inherits(ParserStream, Transform);
ParserStream.prototype._transform = function (chunk, encoding, cb) {
this.unzipStream.write(chunk, encoding, cb);
}
ParserStream.prototype._flush = function (cb) {
var self = this;
this.unzipStream.end(function() {
process.nextTick(function() { self.emit('close'); });
cb();
});
}
ParserStream.prototype.on = function(eventName, fn) {
if (eventName === 'entry') {
return Transform.prototype.on.call(this, 'data', fn);
}
return Transform.prototype.on.call(this, eventName, fn);
}
ParserStream.prototype.drainAll = function () {
this.unzipStream.drainAll();
return this.pipe(new Transform({ objectMode: true, transform: function (d, e, cb) { cb(); } }));
}
module.exports = ParserStream;