Socket
Socket
Sign inDemoInstall

pullstream

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

pullstream - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

4

package.json
{
"name": "pullstream",
"version": "0.1.0",
"version": "0.2.0",
"description": "A stream you can pull data from.",

@@ -28,5 +28,5 @@ "main": "pullstream.js",

"over": "~0.0.5",
"readable-stream": "~0.2.0",
"until-stream": "~0.2.1",
"setimmediate": "~1.0.1"
}
}

@@ -7,13 +7,9 @@ 'use strict';

var inherits = require("util").inherits;
var PassThrough = require('stream').PassThrough;
var UntilStream = require('until-stream');
var over = require('over');
if (!PassThrough) {
PassThrough = require('readable-stream/passthrough');
}
function PullStream(opts) {
var self = this;
this.opts = opts || {};
PassThrough.call(this, opts);
UntilStream.call(this, opts);
this.once('finish', function() {

@@ -32,3 +28,3 @@ self._writesFinished = true;

}
inherits(PullStream, PassThrough);
inherits(PullStream, UntilStream);

@@ -73,3 +69,3 @@ PullStream.prototype.pull = over([

if (!len) {
return PassThrough.prototype.pipe.call(this, destStream);
return UntilStream.prototype.pipe.call(this, destStream);
}

@@ -76,0 +72,0 @@

@@ -1,9 +0,7 @@

pullstream
pullstream [![Build Status](https://travis-ci.org/nearinfinity/node-pullstream.png)](https://travis-ci.org/nearinfinity/node-pullstream)
==========
Tired of getting a firehose worth of data from your streams. This module is here to save the day. PullStream allows
you to pull data when you want and as much as you want.
you to pull data when you want, as much as you want, and until the pattern you want.
[![Build Status](https://travis-ci.org/nearinfinity/node-pullstream.png)](https://travis-ci.org/nearinfinity/node-pullstream)
## Quick Examples

@@ -38,2 +36,3 @@

## PullStream
* [new PullStream([options])](#pullStreamConstructor)
* [pull](#pullStreamPull)

@@ -44,2 +43,3 @@ * [pullUpTo](#pullStreamPullUpTo)

* [end](#pullStreamEnd)
* [reconfigure](#pullStreamReconfigure)

@@ -51,2 +51,12 @@ # API Documentation

<a name="pullStreamConstructor" />
### new PullStream([options])
PullStream inherits from the [until-stream](https://github.com/EvanOxfeld/until-stream) module and passes options to the UntilStream constructor.
__Arguments__
* options (optional)
* pattern - String or Buffer If provided, PullStream will stop pipes when reached
<a name="pullStreamPull" />

@@ -96,3 +106,4 @@ ### ps.pull([number], callback)

Pipes the specified number of bytes to destStream. If a number is not specified pipe will pipe the remainder
of the input stream to destStream.
of the input stream to destStream. If a number is not specified and a pattern is given, pipe will pipe the
input stream to destStream until the pattern is reached. Back-pressure is properly managed.

@@ -159,2 +170,25 @@ __Arguments__

<a name="pullStreamReconfigure" />
### ps.reconfigure([options])
Reconfigure the [until-stream](https://github.com/EvanOxfeld/until-stream) module options. It's unwise
to call this method while piping to a destination stream.
__Arguments__
* options (optional)
* pattern - String or Buffer If provided, PullStream will stop reads or pipes when reached
__Example__
```javascript
var ps = new PullStream();
var outputStream = fs.createWriteStream(path.join(__dirname, 'loremIpsum.out'));
ps.write("Hello\nWorld");
ps.reconfigure({ pattern: '\n' });
ps.pipe(outputStream); //pipe "Hello" to outputStream
ps.reconfigure(); //remove pattern
```
## License

@@ -161,0 +195,0 @@

@@ -387,4 +387,30 @@ 'use strict';

});
},
"use until-stream pattern option": function (t) {
t.expect(2);
var ps = new PullStream({ pattern: 'jumps' });
ps.on('finish', function () {
sourceStream.destroy();
});
var sourceStream = new streamBuffers.ReadableStreamBuffer({
frequency: 0,
chunkSize: 1
});
sourceStream.put("The quick brown fox jumps over the lazy dog");
var writableStream = new streamBuffers.WritableStreamBuffer();
writableStream.on('close', function () {
var str = writableStream.getContentsAsString('utf8');
t.equal(str, 'The quick brown fox ');
var data = ps.read();
t.equal(data.toString(), 'jumps');
ps.end();
t.done();
});
sourceStream.pipe(ps).pipe(writableStream);
}
};
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