How to use the Duplex function from readable-stream

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

152
153
154
155
156
157
158
159
160
161
- __'finish'__:
- __'pipe'__:
- __'unpipe'__:
- __'error'__:

### stream.Duplex
- __'readable'__:
- __'data'__:
- __'end'__:
- __'close'__:
fork icon46
star icon839
watch icon48

10
11
12
13
14
15
16
17
18
19
var pool = new Buffer(10 * 1024)
var used = 0

var Channel = function (name, plex, opts) {
  if (!opts) opts = {}
  stream.Duplex.call(this)

  this.name = name
  this.channel = 0
  this.initiator = false
fork icon29
star icon141
watch icon10

+ 3 other calls in file

32
33
34
35
36
37
38
39
40
41

options = options ? Object.assign({}, options, options.qs) : {}

const multipart = new Multipart()

const retStream = new Duplex({ objectMode: true })

retStream._read = (n) => {}

retStream._write = (file, enc, _next) => {
fork icon16
star icon27
watch icon4

+ 9 other calls in file

29
30
31
32
33
34
35
36
37
38
  return new (stream.Readable)({objectMode:true, highWaterMark:16}).wrap(rs)
}

var Duplexify = function(writable, readable, opts) {
  if (!(this instanceof Duplexify)) return new Duplexify(writable, readable, opts)
  stream.Duplex.call(this, opts)

  this._writable = null
  this._readable = null
  this._readable2 = null
fork icon7
star icon19
watch icon16

+ 13 other calls in file

8
9
10
11
12
13
14
15
16
17
module.exports = DiffStream

function DiffStream (dag, opts) {
  if (!opts) opts = {}
  if (!(this instanceof DiffStream)) return new DiffStream(dag, opts)
  stream.Duplex.call(this, {objectMode: true, highWaterMark: 16})

  var self = this

  this.destroyed = false
fork icon3
star icon32
watch icon8

5383
5384
5385
5386
5387
5388
5389
5390
5391
5392

opts = Object.assign({
  allowHalfOpen: false
}, opts)

stream.Duplex.call(self, opts)

self.channelName = opts.initiator
  ? opts.channelName || randombytes(20).toString('hex')
  : null
fork icon0
star icon0
watch icon0

+ 2 other calls in file