until-stream
Advanced tools
Comparing version 0.1.1 to 0.2.0
{ | ||
"name": "until-stream", | ||
"version": "0.1.1", | ||
"version": "0.2.0", | ||
"description": "A PassThrough stream that stops piping when a pattern is reached ", | ||
@@ -5,0 +5,0 @@ "main": "until.js", |
@@ -75,2 +75,3 @@ until-stream [![Build Status](https://travis-ci.org/EvanOxfeld/until-stream.png)](https://travis-ci.org/EvanOxfeld/until-stream) | ||
* [pipe(destination, [options])](#untilStreamPipe) | ||
* [reconfigure([options])](#untilStreamReconfigure) | ||
@@ -122,2 +123,3 @@ UntilStream also includes stream.Readable and | ||
console.log(hello.toString('utf8')); | ||
us.read(); //matches '\n' pattern! | ||
var world = us.read(); | ||
@@ -157,4 +159,30 @@ console.log(world.toString('utf8')); | ||
<a name="untilStreamReconfigure" /> | ||
### us.reconfigure([options]) | ||
Reconfigure the pattern option. It's unwise to call this method | ||
while piping to a destination stream. | ||
__Arguments__ | ||
* options (optional) | ||
* pattern - String or Buffer If provided, UntilStream will | ||
stop reads or pipes when reached | ||
__Example__ | ||
```javascript | ||
var us = new UntilStream(); | ||
us.write("Hello\nWorld"); | ||
us.reconfigure({ pattern: '\n' }); | ||
var hello = us.read(); | ||
console.log(hello.toString('utf8')); | ||
us.read(); //matches '\n' pattern! | ||
var world = us.read(); | ||
console.log(world.toString('utf8')); | ||
``` | ||
## License | ||
MIT |
27
until.js
@@ -16,14 +16,5 @@ 'use strict'; | ||
function Until(opts) { | ||
var opts = opts || {}; | ||
//todo allow pattern to be set later | ||
if (opts.pattern) { | ||
if (typeof opts.pattern === "string") { | ||
opts.pattern = new Buffer(opts.pattern); | ||
} else if (!opts.pattern instanceof Buffer) { | ||
throw new Error('Invalid pattern type') | ||
} | ||
} | ||
this._opts = opts; | ||
this.reconfigure(opts); | ||
this._buf = Buffers(); | ||
@@ -115,2 +106,16 @@ this._flushing = false; | ||
Until.prototype.reconfigure = function (opts) { | ||
opts = opts || {}; | ||
var pattern = opts && opts.pattern ? opts.pattern : null; | ||
if (pattern) { | ||
if (typeof pattern === "string") { | ||
pattern = new Buffer(pattern); | ||
} else if (!pattern instanceof Buffer) { | ||
throw new Error('Invalid pattern type') | ||
} | ||
} | ||
this._opts = this._opts || opts; | ||
this._opts.pattern = pattern; | ||
}; | ||
function writePipes(data) { | ||
@@ -117,0 +122,0 @@ var rs = this._readableState; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18357
12
359
186