source: trip-planner-front/node_modules/minipass-pipeline/README.md@ 6fe77af

Last change on this file since 6fe77af was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.2 KB
Line 
1# minipass-pipeline
2
3Create a pipeline of streams using Minipass.
4
5Calls `.pipe()` on all the streams in the list. Returns a stream where
6writes got to the first pipe in the chain, and reads are from the last.
7
8Errors are proxied along the chain and emitted on the Pipeline stream.
9
10## USAGE
11
12```js
13const Pipeline = require('minipass-pipeline')
14
15// the list of streams to pipeline together,
16// a bit like `input | transform | output` in bash
17const p = new Pipeline(input, transform, output)
18
19p.write('foo') // writes to input
20p.on('data', chunk => doSomething()) // reads from output stream
21
22// less contrived example (but still pretty contrived)...
23const decode = new bunzipDecoder()
24const unpack = tar.extract({ cwd: 'target-dir' })
25const tbz = new Pipeline(decode, unpack)
26
27fs.createReadStream('archive.tbz').pipe(tbz)
28
29// specify any minipass options if you like, as the first argument
30// it'll only try to pipeline event emitters with a .pipe() method
31const p = new Pipeline({ objectMode: true }, input, transform, output)
32
33// If you don't know the things to pipe in right away, that's fine.
34// use p.push(stream) to add to the end, or p.unshift(stream) to the front
35const databaseDecoderStreamDoohickey = (connectionInfo) => {
36 const p = new Pipeline()
37 logIntoDatabase(connectionInfo).then(connection => {
38 initializeDecoderRing(connectionInfo).then(decoderRing => {
39 p.push(connection, decoderRing)
40 getUpstreamSource(upstream => {
41 p.unshift(upstream)
42 })
43 })
44 })
45 // return to caller right away
46 // emitted data will be upstream -> connection -> decoderRing pipeline
47 return p
48}
49```
50
51Pipeline is a [minipass](http://npm.im/minipass) stream, so it's as
52synchronous as the streams it wraps. It will buffer data until there is a
53reader, but no longer, so make sure to attach your listeners before you
54pipe it somewhere else.
55
56## `new Pipeline(opts = {}, ...streams)`
57
58Create a new Pipeline with the specified Minipass options and any streams
59provided.
60
61## `pipeline.push(stream, ...)`
62
63Attach one or more streams to the pipeline at the end (read) side of the
64pipe chain.
65
66## `pipeline.unshift(stream, ...)`
67
68Attach one or more streams to the pipeline at the start (write) side of the
69pipe chain.
Note: See TracBrowser for help on using the repository browser.