Socket
Socket
Sign inDemoInstall

until-stream

Package Overview
Dependencies
Maintainers
1
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

until-stream - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

test/reconfigurePattern.js

2

package.json
{
"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

@@ -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;

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc