How to use the PassThrough function from readable-stream

Find comprehensive JavaScript readable-stream.PassThrough code examples handpicked from public code repositorys.

6
7
8
9
10
11
12
13
14
15

var readableStream = require('readable-stream');
var Readable = readableStream.Readable;
var Writable = readableStream.Writable;
var Transform = readableStream.Transform;
var PassThrough = readableStream.PassThrough;

var immutableClass = require('immutable-class');
var generalArraysEqual = immutableClass.generalArraysEqual;
var generalEqual = immutableClass.generalEqual;
fork icon62
star icon380
watch icon58

238
239
240
241
242
243
244
245
246
247

### Keep stream open after it ends
```js
const stream = require('readable-stream')

const pts1 = new stream.PassThrough({ end: false })
const pts2 = new Stream.PassThrough()

// when stream1 ends, stream2 is kept open
pts1.pipe(pts2)
fork icon46
star icon839
watch icon48

+ 3 other calls in file

13
14
15
16
17
18
19
20
21
22
this.conn = null;
this.completed = false;
this.inprogress = 0;

var accept = new stream.PassThrough(options.accept);
var transmit = new stream.PassThrough(options.transmit);

if (! options.encoding) options.encoding = this.options.defaultEncoding;
if (options.encoding == 'buffer') delete options.encoding;
if (options.encoding && (!options.accept || !options.accept.encoding)) {
fork icon11
star icon51
watch icon10

+ 31 other calls in file

48
49
50
51
52
53
54
55
56
57
        ? this._sendBufferToChild(child)
        : child.drain = child.dest.once('drain',function() { self._sendBufferToChild(child) });
}

StreamReplay.prototype.spawn = function () {
    var out = new stream.PassThrough();
    this.pipe(out);
    var self = this;
    out.once('end',function(){ self.unpipe(out) });
    return out;
fork icon11
star icon51
watch icon10

22
23
24
25
26
27
28
29
30
31
}
// either css hasn't been updated, and is ready to serve
// or attach a listener to when css will be updated
// and send when ready
if (!state.cssReady) {
  const ts = new stream.PassThrough()
  state.once('css:ready', function () {
    state.cssBuf.duplicate().pipe(ts)
  })
  return ts
fork icon102
star icon0
watch icon3

63
64
65
66
67
68
69
70
71
72
  this._torrent.deselect(this._startPiece, this._endPiece, false)
}

createReadStream (opts) {
  if (this.length === 0) {
    const empty = new PassThrough()
    process.nextTick(() => {
      empty.end()
    })
    return empty
fork icon0
star icon0
watch icon1

2
3
4
5
6
7
8
9
10
11

module.exports = async function*(iterable) {
  // TODO: Remove once node v8 is deprecated
  // Detect and upgrade old streams
  if (iterable.pipe && !iterable[Symbol.asyncIterator]) {
    iterable = iterable.pipe(new PassThrough());
  }
  const saxesParser = new SaxesParser();
  let error;
  saxesParser.on('error', err => {
fork icon0
star icon0
watch icon1

139
140
141
142
143
144
145
146
147
148
for (const {sheetNo, path, tempFileCleanupCallback} of waitingWorkSheets) {
  let fileStream = fs.createReadStream(path);
  // TODO: Remove once node v8 is deprecated
  // Detect and upgrade old fileStreams
  if (!fileStream[Symbol.asyncIterator]) {
    fileStream = fileStream.pipe(new PassThrough());
  }
  yield* this._parseWorksheet(fileStream, sheetNo);
  tempFileCleanupCallback();
}
fork icon0
star icon0
watch icon182