match-stream
Advanced tools
Comparing version 0.0.0 to 0.0.1
19
match.js
@@ -37,7 +37,22 @@ 'use strict'; | ||
if (index >= 0) { | ||
this._matchFn(this._bufs.splice(0, index).toBuffer(), pattern, this._bufs.toBuffer()); | ||
processMatches.call(this, index, pattern, callback); | ||
} else { | ||
this._matchFn(this._bufs.splice(0, this._bufs.length - chunk.length)); | ||
callback(); | ||
} | ||
callback(); | ||
}; | ||
function processMatches(index, pattern, callback) { | ||
var buf = this._bufs.splice(0, index).toBuffer(); | ||
if (this._opts.consume) { | ||
this._bufs.splice(0, pattern.length); | ||
} | ||
this._matchFn(buf, pattern, this._bufs.toBuffer()); | ||
index = this._bufs.indexOf(pattern); | ||
if (index > 0 || this._opts.consume && index === 0) { | ||
process.nextTick(processMatches.bind(this, index, pattern, callback)); | ||
} else { | ||
callback(); | ||
} | ||
} |
{ | ||
"name": "match-stream", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Match a pattern within a stream", | ||
@@ -5,0 +5,0 @@ "main": "match.js", |
@@ -12,4 +12,6 @@ match-stream [![Build Status](https://travis-ci.org/EvanOxfeld/match-stream.png)](https://travis-ci.org/EvanOxfeld/match-stream) | ||
## Quick Example | ||
## Quick Examples | ||
### End stream on match | ||
```javascript | ||
@@ -44,2 +46,25 @@ var MatchStream = require('match-stream'); | ||
### Split stream | ||
```javascript | ||
var MatchStream = require('match-stream'); | ||
var fs = require('fs'); | ||
var line = ""; | ||
var loremLines = []; | ||
var ms = new MatchStream({ pattern: '.', consume: true}, function (buf, matched, extra) { | ||
line += buf.toString(); | ||
if (matched) { | ||
loremLines.push(line.trim()); | ||
line = ""; | ||
} | ||
}); | ||
fs.createReadStream('lorem.txt') | ||
.pipe(ms) | ||
.once('end', function() { | ||
console.log(loremLines); | ||
}); | ||
``` | ||
## License | ||
@@ -46,0 +71,0 @@ |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
38781
19
153
76
2