mississippi
Advanced tools
Comparing version 1.1.1 to 1.2.0
@@ -7,2 +7,4 @@ module.exports.pipe = require('pump') | ||
module.exports.concat = require('concat-stream') | ||
module.exports.finished = require('end-of-stream') | ||
module.exports.finished = require('end-of-stream') | ||
module.exports.from = require('from2') | ||
module.exports.to = require('flush-write-stream') |
{ | ||
"name": "mississippi", | ||
"version": "1.1.1", | ||
"version": "1.2.0", | ||
"description": "a collection of useful streams", | ||
@@ -15,2 +15,4 @@ "main": "index.js", | ||
"end-of-stream": "^1.1.0", | ||
"flush-write-stream": "^1.0.0", | ||
"from2": "^2.1.0", | ||
"pump": "^1.0.0", | ||
@@ -17,0 +19,0 @@ "pumpify": "^1.3.3", |
122
readme.md
@@ -20,2 +20,4 @@ # mississippi | ||
- [through](#through) | ||
- [from](#from) | ||
- [to](#to) | ||
- [concat](#concat) | ||
@@ -130,3 +132,3 @@ - [finished](#finished) | ||
Take two separate streams, a writable and a readable, and turn them into a single duplex (readable and writable) stream. | ||
Take two separate streams, a writable and a readable, and turn them into a single [duplex (readable and writable) stream](https://nodejs.org/api/stream.html#stream_class_stream_duplex). | ||
@@ -181,6 +183,6 @@ The returned stream will emit data from the readable. When you write to it it writes to the writable. | ||
function (chunk, enc, cb) { | ||
cb(chunk.toString().toUpperCase()) | ||
cb(chunk.toString().toUpperCase()) | ||
}, | ||
function (cb) { | ||
cb('ONE LAST BIT OF UPPERCASE') | ||
cb('ONE LAST BIT OF UPPERCASE') | ||
} | ||
@@ -195,2 +197,99 @@ ) | ||
### from | ||
#####`miss.from([opts], read)` | ||
Make a custom [readable stream](https://nodejs.org/docs/latest/api/stream.html#stream_class_stream_readable). | ||
`opts` contains the options to pass on to the ReadableStream constructor e.g. for creating a readable object stream (or use the shortcut `miss.from.obj([...])`). | ||
Returns a readable stream that calls `read(size, next)` when data is requested from the stream. | ||
- `size` is the recommended amount of data (in bytes) to retrieve. | ||
- `next(err, chunk)` should be called when you're ready to emit more data. | ||
#### original module | ||
`miss.from` is provided by [`require('from2')`](https://npmjs.org/from2) | ||
#### example | ||
```js | ||
function fromString(string) { | ||
return miss.from(function(size, next) { | ||
// if there's no more content | ||
// left in the string, close the stream. | ||
if (string.length <= 0) return next(null, null) | ||
// Pull in a new chunk of text, | ||
// removing it from the string. | ||
var chunk = string.slice(0, size) | ||
string = string.slice(size) | ||
// Emit "chunk" from the stream. | ||
next(null, chunk) | ||
}) | ||
} | ||
// pipe "hello world" out | ||
// to stdout. | ||
fromString('hello world').pipe(process.stdout) | ||
``` | ||
### to | ||
#####`miss.to([options], write, [flush])` | ||
Make a custom [writable stream](https://nodejs.org/docs/latest/api/stream.html#stream_class_stream_writable). | ||
`opts` contains the options to pass on to the WritableStream constructor e.g. for creating a readable object stream (or use the shortcut `miss.to.obj([...])`). | ||
Returns a writable stream that calls `write(data, enc, cb)` when data is written to the stream. | ||
- `data` is the received data to write the destination. | ||
- `enc` encoding of the piece of data received. | ||
- `next(err, chunk)` should be called when you're ready to write more data, or encountered an error. | ||
`flush(cb)` is called before `finish` is emitted and allows for cleanup steps to occur. | ||
#### original module | ||
`miss.to` is provided by [`require('flush-write-stream')`](https://npmjs.org/flush-write-stream) | ||
#### example | ||
```js | ||
var ws = miss.to(write, flush) | ||
ws.on('finish', function () { | ||
console.log('finished') | ||
}) | ||
ws.write('hello') | ||
ws.write('world') | ||
ws.end() | ||
function write (data, enc, cb) { | ||
// i am your normal ._write method | ||
console.log('writing', data.toString()) | ||
cb() | ||
} | ||
function flush (cb) { | ||
// i am called before finish is emitted | ||
setTimeout(cb, 1000) // wait 1 sec | ||
} | ||
``` | ||
If you run the above it will produce the following output | ||
``` | ||
writing hello | ||
writing world | ||
(nothing happens for 1 sec) | ||
finished | ||
``` | ||
### concat | ||
@@ -215,17 +314,17 @@ | ||
var concat = require('concat-stream') | ||
var readStream = fs.createReadStream('cat.png') | ||
var concatStream = concat(gotPicture) | ||
readStream.on('error', handleError) | ||
readStream.pipe(concatStream) | ||
function gotPicture(imageBuffer) { | ||
// imageBuffer is all of `cat.png` as a node.js Buffer | ||
// imageBuffer is all of `cat.png` as a node.js Buffer | ||
} | ||
function handleError(err) { | ||
// handle your error appropriately here, e.g.: | ||
console.error(err) // print the error to STDERR | ||
process.exit(1) // exit program with non-zero exit code | ||
// handle your error appropriately here, e.g.: | ||
console.error(err) // print the error to STDERR | ||
process.exit(1) // exit program with non-zero exit code | ||
} | ||
@@ -259,1 +358,2 @@ ``` | ||
``` | ||
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
12558
9
354
9
+ Addedflush-write-stream@^1.0.0
+ Addedfrom2@^2.1.0
+ Addedflush-write-stream@1.1.1(transitive)
+ Addedfrom2@2.3.0(transitive)