bl 1.1.1 → 1.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bl.js +35 -19
- package/package.json +1 -1
package/bl.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
var DuplexStream = require('readable-stream/duplex')
|
|
2
2
|
, util = require('util')
|
|
3
3
|
|
|
4
|
+
|
|
4
5
|
function BufferList (callback) {
|
|
5
6
|
if (!(this instanceof BufferList))
|
|
6
7
|
return new BufferList(callback)
|
|
@@ -11,17 +12,17 @@ function BufferList (callback) {
|
|
|
11
12
|
if (typeof callback == 'function') {
|
|
12
13
|
this._callback = callback
|
|
13
14
|
|
|
14
|
-
var piper = function (err) {
|
|
15
|
+
var piper = function piper (err) {
|
|
15
16
|
if (this._callback) {
|
|
16
17
|
this._callback(err)
|
|
17
18
|
this._callback = null
|
|
18
19
|
}
|
|
19
20
|
}.bind(this)
|
|
20
21
|
|
|
21
|
-
this.on('pipe', function (src) {
|
|
22
|
+
this.on('pipe', function onPipe (src) {
|
|
22
23
|
src.on('error', piper)
|
|
23
24
|
})
|
|
24
|
-
this.on('unpipe', function (src) {
|
|
25
|
+
this.on('unpipe', function onUnpipe (src) {
|
|
25
26
|
src.removeListener('error', piper)
|
|
26
27
|
})
|
|
27
28
|
} else {
|
|
@@ -31,9 +32,11 @@ function BufferList (callback) {
|
|
|
31
32
|
DuplexStream.call(this)
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
|
|
34
36
|
util.inherits(BufferList, DuplexStream)
|
|
35
37
|
|
|
36
|
-
|
|
38
|
+
|
|
39
|
+
BufferList.prototype._offset = function _offset (offset) {
|
|
37
40
|
var tot = 0, i = 0, _t
|
|
38
41
|
for (; i < this._bufs.length; i++) {
|
|
39
42
|
_t = tot + this._bufs[i].length
|
|
@@ -43,7 +46,8 @@ BufferList.prototype._offset = function (offset) {
|
|
|
43
46
|
}
|
|
44
47
|
}
|
|
45
48
|
|
|
46
|
-
|
|
49
|
+
|
|
50
|
+
BufferList.prototype.append = function append (buf) {
|
|
47
51
|
var i = 0
|
|
48
52
|
, newBuf
|
|
49
53
|
|
|
@@ -68,21 +72,26 @@ BufferList.prototype.append = function (buf) {
|
|
|
68
72
|
return this
|
|
69
73
|
}
|
|
70
74
|
|
|
71
|
-
|
|
75
|
+
|
|
76
|
+
BufferList.prototype._write = function _write (buf, encoding, callback) {
|
|
72
77
|
this.append(buf)
|
|
73
|
-
|
|
78
|
+
|
|
79
|
+
if (typeof callback == 'function')
|
|
74
80
|
callback()
|
|
75
81
|
}
|
|
76
82
|
|
|
77
|
-
|
|
83
|
+
|
|
84
|
+
BufferList.prototype._read = function _read (size) {
|
|
78
85
|
if (!this.length)
|
|
79
86
|
return this.push(null)
|
|
87
|
+
|
|
80
88
|
size = Math.min(size, this.length)
|
|
81
89
|
this.push(this.slice(0, size))
|
|
82
90
|
this.consume(size)
|
|
83
91
|
}
|
|
84
92
|
|
|
85
|
-
|
|
93
|
+
|
|
94
|
+
BufferList.prototype.end = function end (chunk) {
|
|
86
95
|
DuplexStream.prototype.end.call(this, chunk)
|
|
87
96
|
|
|
88
97
|
if (this._callback) {
|
|
@@ -91,15 +100,18 @@ BufferList.prototype.end = function (chunk) {
|
|
|
91
100
|
}
|
|
92
101
|
}
|
|
93
102
|
|
|
94
|
-
|
|
103
|
+
|
|
104
|
+
BufferList.prototype.get = function get (index) {
|
|
95
105
|
return this.slice(index, index + 1)[0]
|
|
96
106
|
}
|
|
97
107
|
|
|
98
|
-
|
|
108
|
+
|
|
109
|
+
BufferList.prototype.slice = function slice (start, end) {
|
|
99
110
|
return this.copy(null, 0, start, end)
|
|
100
111
|
}
|
|
101
112
|
|
|
102
|
-
|
|
113
|
+
|
|
114
|
+
BufferList.prototype.copy = function copy (dst, dstStart, srcStart, srcEnd) {
|
|
103
115
|
if (typeof srcStart != 'number' || srcStart < 0)
|
|
104
116
|
srcStart = 0
|
|
105
117
|
if (typeof srcEnd != 'number' || srcEnd > this.length)
|
|
@@ -162,11 +174,11 @@ BufferList.prototype.copy = function (dst, dstStart, srcStart, srcEnd) {
|
|
|
162
174
|
return dst
|
|
163
175
|
}
|
|
164
176
|
|
|
165
|
-
BufferList.prototype.toString = function (encoding, start, end) {
|
|
177
|
+
BufferList.prototype.toString = function toString (encoding, start, end) {
|
|
166
178
|
return this.slice(start, end).toString(encoding)
|
|
167
179
|
}
|
|
168
180
|
|
|
169
|
-
BufferList.prototype.consume = function (bytes) {
|
|
181
|
+
BufferList.prototype.consume = function consume (bytes) {
|
|
170
182
|
while (this._bufs.length) {
|
|
171
183
|
if (bytes >= this._bufs[0].length) {
|
|
172
184
|
bytes -= this._bufs[0].length
|
|
@@ -181,7 +193,8 @@ BufferList.prototype.consume = function (bytes) {
|
|
|
181
193
|
return this
|
|
182
194
|
}
|
|
183
195
|
|
|
184
|
-
|
|
196
|
+
|
|
197
|
+
BufferList.prototype.duplicate = function duplicate () {
|
|
185
198
|
var i = 0
|
|
186
199
|
, copy = new BufferList()
|
|
187
200
|
|
|
@@ -191,12 +204,14 @@ BufferList.prototype.duplicate = function () {
|
|
|
191
204
|
return copy
|
|
192
205
|
}
|
|
193
206
|
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
this.length = 0
|
|
197
|
-
this.
|
|
207
|
+
|
|
208
|
+
BufferList.prototype.destroy = function destroy () {
|
|
209
|
+
this._bufs.length = 0
|
|
210
|
+
this.length = 0
|
|
211
|
+
this.push(null)
|
|
198
212
|
}
|
|
199
213
|
|
|
214
|
+
|
|
200
215
|
;(function () {
|
|
201
216
|
var methods = {
|
|
202
217
|
'readDoubleBE' : 8
|
|
@@ -224,4 +239,5 @@ BufferList.prototype.destroy = function () {
|
|
|
224
239
|
}
|
|
225
240
|
}())
|
|
226
241
|
|
|
242
|
+
|
|
227
243
|
module.exports = BufferList
|