source: trip-planner-front/node_modules/bl/bl.js@ 76712b2

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

initial commit

  • Property mode set to 100644
File size: 2.0 KB
Line 
1'use strict'
2
3const DuplexStream = require('readable-stream').Duplex
4const inherits = require('inherits')
5const BufferList = require('./BufferList')
6
7function BufferListStream (callback) {
8 if (!(this instanceof BufferListStream)) {
9 return new BufferListStream(callback)
10 }
11
12 if (typeof callback === 'function') {
13 this._callback = callback
14
15 const piper = function piper (err) {
16 if (this._callback) {
17 this._callback(err)
18 this._callback = null
19 }
20 }.bind(this)
21
22 this.on('pipe', function onPipe (src) {
23 src.on('error', piper)
24 })
25 this.on('unpipe', function onUnpipe (src) {
26 src.removeListener('error', piper)
27 })
28
29 callback = null
30 }
31
32 BufferList._init.call(this, callback)
33 DuplexStream.call(this)
34}
35
36inherits(BufferListStream, DuplexStream)
37Object.assign(BufferListStream.prototype, BufferList.prototype)
38
39BufferListStream.prototype._new = function _new (callback) {
40 return new BufferListStream(callback)
41}
42
43BufferListStream.prototype._write = function _write (buf, encoding, callback) {
44 this._appendBuffer(buf)
45
46 if (typeof callback === 'function') {
47 callback()
48 }
49}
50
51BufferListStream.prototype._read = function _read (size) {
52 if (!this.length) {
53 return this.push(null)
54 }
55
56 size = Math.min(size, this.length)
57 this.push(this.slice(0, size))
58 this.consume(size)
59}
60
61BufferListStream.prototype.end = function end (chunk) {
62 DuplexStream.prototype.end.call(this, chunk)
63
64 if (this._callback) {
65 this._callback(null, this.slice())
66 this._callback = null
67 }
68}
69
70BufferListStream.prototype._destroy = function _destroy (err, cb) {
71 this._bufs.length = 0
72 this.length = 0
73 cb(err)
74}
75
76BufferListStream.prototype._isBufferList = function _isBufferList (b) {
77 return b instanceof BufferListStream || b instanceof BufferList || BufferListStream.isBufferList(b)
78}
79
80BufferListStream.isBufferList = BufferList.isBufferList
81
82module.exports = BufferListStream
83module.exports.BufferListStream = BufferListStream
84module.exports.BufferList = BufferList
Note: See TracBrowser for help on using the repository browser.