New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

bufferstream

Package Overview
Dependencies
Maintainers
1
Versions
36
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bufferstream - npm Package Compare versions

Comparing version 0.4.6 to 0.4.7

example/shortcut.js

6

example/split.js

@@ -15,5 +15,11 @@ var BufferStream = require('../bufferstream');

stream.on('data', function (chunk) {
console.log("got data '%s'", chunk.toString());
});
console.log("writing stream is",
stream.write("buffer:stream//23:42//disabled") && "ok" || "failed");
stream.end();
console.log("stream content:", stream.toString());

2

package.json
{ "name": "bufferstream"
, "description": "painless stream buffering and cutting"
, "version": "0.4.6"
, "version": "0.4.7"
, "homepage": "https://github.com/dodo/node-bufferstream"

@@ -5,0 +5,0 @@ , "author": "dodo (https://github.com/dodo)"

@@ -23,3 +23,8 @@ # BufferStream

* `size` defines buffer level or sets buffer to given size (see ↓`setSize` for more)
* `split` short form for:
```javascript
stream.split(token, function (chunk) {stream.emit('data', chunk)})
```
### stream.setSize

@@ -78,8 +83,11 @@

stream.on('split', function (chunk, token) {…})
stream.split(token, function (chunk, token) {…}) // only get called for given token
stream.split(token, function (chunk, token) {…}) // only get called for this particular token
```
BufferStream slices its buffer to the first position of on of the splitter tokens and emits it.
whenever the stream is enabled it will try to find all splitter token in `stream.buffer`,
cut it off and emit the chunk (without token) as __split__ event.
this data will be lost when not handled.
the chunk is the cut off of `stream.buffer` without the token.
__Warning:__ try to avoid calling `stream.emit('data', newchunk)` more than one time, because this will likely throw `Error: Offset is out of bounds`.

@@ -163,1 +171,29 @@

## FAQ
> I'm not sure from your readme what the split event emits?
you can specify more than one split token .. so it's emitted whenever
a token is found.
> does it emit the buffer up to the just before the token starts?
yes.
> also, does it join buffers together if they do not already end in a token?
when size is `flexible` it joins everything together what it gets to
one buffer (accessible through `stream.buffer` or
`stream.getBuffer()`)
whenever it gets data, it will try to find all tokens
> in other words, can I use this to rechunk a stream so that the chunks always break on newlines, for example?
yes.
```javascript
stream = new BufferStream({size:'flexible'});
stream.split('\n', function (line) { // line doesn't have a '\n' anymore
stream.emit('data', line); // Buffer.isBuffer(line) === true
});
```

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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