no way to delay start of data flow
Currently the pcap-parser always starts on the next tick due to this code:
process.nextTick(this.stream.resume.bind(this.stream));
Even if you attempt to call parser.stream.pause() after creating the parser it will still be summarily resume()'d on the nextTick(). It would be nice if there was an option to the constructor indicating that the stream should remain paused.
Alternatively, implementing the Readable interface provided by streams2 would provide a similar effect.
I haven't looked at writing a pull request because I heard a rumor that a conversion to streams2 may be in the works. Is that true?
Thanks!
For whatever its worth, I worked around this by wrapping pcap-parser in a Readable. I used something like this:
var Readable = require('stream').Readable;
var stream = new Readable({objectMode: true});
var parser = new PcapParser(file);
parser.on('packet', function(packet) {
var res = stream.push(packet);
if (!res) {
parser.stream.pause();
}
});
stream._read = function() {
parser.stream.resume();
};
stream.on('readable', function() {
var packet = stream.read();
// process packet...
});
// Don't start the process until ready for data...
stream.read(0);
I ended up wrapping this up into a module in node-pcap-stream. I'd be happy to convert this to a pull request if you think it makes sense to incorporate directly into node-pcap-parser. Thanks.