dmotz / stream-snitch Goto Github PK
View Code? Open in Web Editor NEW๐ Event emitter for watching text streams with regex patterns
License: MIT License
๐ Event emitter for watching text streams with regex patterns
License: MIT License
It is not 100% guaranteed that stream-snitch will find a match even if the data you are looking for is present in the stream.
This happens specially if the length of the data is bigger than your chunks and when the buffer size is small.
const StreamSnitch = require('stream-snitch');
let sn = new StreamSnitch(
/ab(\d{1,3})cd/g,
(m) => {console.dir(m[1])},
{bufferCap: 100}
);
sn.write('--------ab');
sn.write('123');
sn.write('cd');
In the case above, as soon as the 123
is written the buffer is flushed.
When using piping a child process stdout, the chunk sizes can get very small (example), and although increasing buffer cap will reduce the frequency of dropped matches, it still occurs.
Add a maxMatchSize
to the options where the user can set the max size of the matching string (in the example below it would be 7).
When this option !== undefined the clearBuffer
method would let the last maxMatchSize
bytes when clearing the buffer.
StreamSnitch.prototype.clearBuffer = function() {
if(typeof options.maxMatchSize !== 'undefined'){
this._buffer = this._buffer.slice(-maxMatchSize);
}else{
this._buffer = '';
}
return this;
}
If "/g" mode isn't set in regexp then while (match = this.regex.exec(this._buffer)) {
can't leave loop, there should be
if (!this.regex.global) { break; }
inside this while
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.