bufferstream
Advanced tools
Comparing version 0.4.6 to 0.4.7
@@ -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()); |
{ "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
AI-detected possible typosquat
Supply chain riskAI has identified this package as a potential typosquat of a more popular package. This suggests that the package may be intentionally mimicking another package's name, description, or other metadata.
Found 1 instance in 1 package
15400
12
26
197
1