bufferstream
Advanced tools
Comparing version 0.1.1 to 0.1.2
{ "name": "bufferstream" | ||
, "description": "painless stream buffering and cutting" | ||
, "version": "0.1.1" | ||
, "version": "0.1.2" | ||
, "homepage": "https://github.com/dodo/node-bufferstream" | ||
@@ -5,0 +5,0 @@ , "author": "dodo (https://github.com/dodo)" |
@@ -0,2 +1,80 @@ | ||
# BufferStream | ||
painless stream buffering, cutting and piping. | ||
## install | ||
npm install bufferstream | ||
## api | ||
BufferStream is a full node.js [Stream](http://nodejs.org/docs/v0.4.7/api/streams.html) so it has apis of both [Writeable Stream](http://nodejs.org/docs/v0.4.7/api/streams.html#writable_Stream) and [Readable Stream](http://nodejs.org/docs/v0.4.7/api/streams.html#readable_Stream). | ||
### BufferStream | ||
stream = new BufferStream([encoding]) | ||
* `encoding` default encoding for writing strings | ||
### stream.enable | ||
stream.enable() | ||
enables stream buffering __default__ | ||
### stream.disable | ||
stream.disable() | ||
flushes buffer and disables stream buffering. | ||
BufferStream now pipes all data as long as the output accepting data. | ||
when the output is draining BufferStream will buffer all input temporary. | ||
### stream.split | ||
stream.split(token, ...) | ||
stream.split(tokens) // Array | ||
* `token[s]` buffer splitters (should be String or Buffer) | ||
each time BufferStream finds a splitter token in the input data it will emit a __split__ event. | ||
this also works for binary data. | ||
### Event: 'split' | ||
stream.on('split', function (chunk, token) {…}) | ||
stream.split(token, function (chunk, token) {…}) // only get called for given token | ||
BufferStream slices its buffer to the first position of on of the splitter tokens and emits it. | ||
this data will be lost when not handled. | ||
### stream.getBuffer | ||
stream.getBuffer() | ||
// or just | ||
stream.buffer | ||
returns its [Buffer](http://nodejs.org/docs/v0.4.7/api/buffers.html). | ||
### stream.toString | ||
stream.toString() | ||
shortcut for `stream.buffer.toString()` | ||
## example | ||
BufferStream = require('bufferstream') | ||
stream = new BufferStream('utf8') | ||
stream.split('//', ':') | ||
stream.on('split', function (chunk, token) { | ||
console.log("got '%s' by '%s'", chunk.toString(), token.toString()) | ||
}) | ||
stream.write("buffer:stream//23") | ||
console.log(stream.toString()) | ||
results in | ||
got 'buffer' by ':' | ||
got 'stream' by '//' | ||
23 | ||
* https://github.com/dodo/node-bufferstream/blob/master/example/split.js |
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
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
7453
7
8
81
2