bare-buffer 2.6.0 → 2.7.0
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/global.js +1 -0
- package/index.js +249 -98
- package/lib/ascii.js +3 -3
- package/lib/base64.js +1 -1
- package/lib/hex.js +1 -1
- package/lib/utf16le.js +1 -1
- package/package.json +6 -3
- package/prebuilds/android-arm/bare-buffer.bare +0 -0
- package/prebuilds/android-arm64/bare-buffer.bare +0 -0
- package/prebuilds/android-ia32/bare-buffer.bare +0 -0
- package/prebuilds/android-x64/bare-buffer.bare +0 -0
- package/prebuilds/darwin-arm64/bare-buffer.bare +0 -0
- package/prebuilds/darwin-x64/bare-buffer.bare +0 -0
- package/prebuilds/ios-arm64/bare-buffer.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-buffer.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-buffer.bare +0 -0
- package/prebuilds/linux-arm64/bare-buffer.bare +0 -0
- package/prebuilds/linux-x64/bare-buffer.bare +0 -0
- package/prebuilds/win32-arm64/bare-buffer.bare +0 -0
- package/prebuilds/win32-x64/bare-buffer.bare +0 -0
package/global.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
global.Buffer = require('.')
|
package/index.js
CHANGED
|
@@ -8,24 +8,24 @@ const binding = require('./binding')
|
|
|
8
8
|
|
|
9
9
|
let poolSize = 0
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
module.exports = exports = class Buffer extends Uint8Array {
|
|
12
12
|
static {
|
|
13
13
|
binding.tag(this)
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
static get poolSize
|
|
16
|
+
static get poolSize() {
|
|
17
17
|
return poolSize
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
static set poolSize
|
|
20
|
+
static set poolSize(value) {
|
|
21
21
|
poolSize = Math.max(0, value)
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
[Symbol.species]
|
|
24
|
+
[Symbol.species]() {
|
|
25
25
|
return Buffer
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
copy
|
|
28
|
+
copy(target, targetStart = 0, sourceStart = 0, sourceEnd = this.byteLength) {
|
|
29
29
|
let source = this
|
|
30
30
|
|
|
31
31
|
if (targetStart < 0) targetStart = 0
|
|
@@ -39,14 +39,18 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
39
39
|
if (sourceEnd <= sourceStart) return 0
|
|
40
40
|
if (sourceEnd > source.byteLength) sourceEnd = source.byteLength
|
|
41
41
|
|
|
42
|
-
if (sourceEnd - sourceStart > targetLength)
|
|
42
|
+
if (sourceEnd - sourceStart > targetLength) {
|
|
43
|
+
sourceEnd = sourceStart + targetLength
|
|
44
|
+
}
|
|
43
45
|
|
|
44
46
|
const sourceLength = sourceEnd - sourceStart
|
|
45
47
|
|
|
46
48
|
if (source === target) {
|
|
47
49
|
target.copyWithin(targetStart, sourceStart, sourceEnd)
|
|
48
50
|
} else {
|
|
49
|
-
if (sourceStart !== 0 || sourceEnd !== source.byteLength)
|
|
51
|
+
if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
|
|
52
|
+
source = source.subarray(sourceStart, sourceEnd)
|
|
53
|
+
}
|
|
50
54
|
|
|
51
55
|
target.set(source, targetStart)
|
|
52
56
|
}
|
|
@@ -54,7 +58,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
54
58
|
return sourceLength
|
|
55
59
|
}
|
|
56
60
|
|
|
57
|
-
equals
|
|
61
|
+
equals(target) {
|
|
58
62
|
const source = this
|
|
59
63
|
|
|
60
64
|
if (source === target) return true
|
|
@@ -64,7 +68,13 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
64
68
|
return binding.compare(source, target) === 0
|
|
65
69
|
}
|
|
66
70
|
|
|
67
|
-
compare
|
|
71
|
+
compare(
|
|
72
|
+
target,
|
|
73
|
+
targetStart = 0,
|
|
74
|
+
targetEnd = target.byteLength,
|
|
75
|
+
sourceStart = 0,
|
|
76
|
+
sourceEnd = this.byteLength
|
|
77
|
+
) {
|
|
68
78
|
let source = this
|
|
69
79
|
|
|
70
80
|
if (source === target) return 0
|
|
@@ -83,14 +93,18 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
83
93
|
if (sourceEnd < sourceStart) sourceEnd = sourceStart
|
|
84
94
|
if (sourceEnd > source.byteLength) sourceEnd = source.byteLength
|
|
85
95
|
|
|
86
|
-
if (sourceStart !== 0 || sourceEnd !== source.byteLength)
|
|
96
|
+
if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
|
|
97
|
+
source = source.subarray(sourceStart, sourceEnd)
|
|
98
|
+
}
|
|
87
99
|
|
|
88
|
-
if (targetStart !== 0 || targetEnd !== target.byteLength)
|
|
100
|
+
if (targetStart !== 0 || targetEnd !== target.byteLength) {
|
|
101
|
+
target = target.subarray(targetStart, targetEnd)
|
|
102
|
+
}
|
|
89
103
|
|
|
90
104
|
return binding.compare(source, target)
|
|
91
105
|
}
|
|
92
106
|
|
|
93
|
-
fill
|
|
107
|
+
fill(value, offset = 0, end = this.byteLength, encoding = 'utf8') {
|
|
94
108
|
if (typeof value === 'string') {
|
|
95
109
|
// fill(string, encoding)
|
|
96
110
|
if (typeof offset === 'string') {
|
|
@@ -98,7 +112,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
98
112
|
offset = 0
|
|
99
113
|
end = this.byteLength
|
|
100
114
|
|
|
101
|
-
|
|
115
|
+
// fill(string, offset, encoding)
|
|
102
116
|
} else if (typeof end === 'string') {
|
|
103
117
|
encoding = end
|
|
104
118
|
end = this.byteLength
|
|
@@ -128,36 +142,42 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
128
142
|
return this
|
|
129
143
|
}
|
|
130
144
|
|
|
131
|
-
includes
|
|
145
|
+
includes(value, offset, encoding) {
|
|
132
146
|
return this.indexOf(value, offset, encoding) !== -1
|
|
133
147
|
}
|
|
134
148
|
|
|
135
|
-
indexOf
|
|
149
|
+
indexOf(value, offset = 0, encoding) {
|
|
136
150
|
if (typeof value === 'number') return super.indexOf(value & 0xff, offset)
|
|
137
151
|
|
|
138
152
|
return bidirectionalIndexOf(this, value, offset, encoding, true /* first */)
|
|
139
153
|
}
|
|
140
154
|
|
|
141
|
-
lastIndexOf
|
|
142
|
-
if (typeof value === 'number')
|
|
155
|
+
lastIndexOf(value, offset = this.byteLength - 1, encoding) {
|
|
156
|
+
if (typeof value === 'number') {
|
|
157
|
+
return super.lastIndexOf(value & 0xff, offset)
|
|
158
|
+
}
|
|
143
159
|
|
|
144
160
|
return bidirectionalIndexOf(this, value, offset, encoding, false /* last */)
|
|
145
161
|
}
|
|
146
162
|
|
|
147
|
-
swap16
|
|
163
|
+
swap16() {
|
|
148
164
|
const length = this.byteLength
|
|
149
165
|
|
|
150
|
-
if (length % 2 !== 0)
|
|
166
|
+
if (length % 2 !== 0) {
|
|
167
|
+
throw new RangeError('Buffer size must be a multiple of 16-bits')
|
|
168
|
+
}
|
|
151
169
|
|
|
152
170
|
for (let i = 0; i < length; i += 2) swap(this, i, i + 1)
|
|
153
171
|
|
|
154
172
|
return this
|
|
155
173
|
}
|
|
156
174
|
|
|
157
|
-
swap32
|
|
175
|
+
swap32() {
|
|
158
176
|
const length = this.byteLength
|
|
159
177
|
|
|
160
|
-
if (length % 4 !== 0)
|
|
178
|
+
if (length % 4 !== 0) {
|
|
179
|
+
throw new RangeError('Buffer size must be a multiple of 32-bits')
|
|
180
|
+
}
|
|
161
181
|
|
|
162
182
|
for (let i = 0; i < length; i += 4) {
|
|
163
183
|
swap(this, i, i + 3)
|
|
@@ -167,10 +187,12 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
167
187
|
return this
|
|
168
188
|
}
|
|
169
189
|
|
|
170
|
-
swap64
|
|
190
|
+
swap64() {
|
|
171
191
|
const length = this.byteLength
|
|
172
192
|
|
|
173
|
-
if (length % 8 !== 0)
|
|
193
|
+
if (length % 8 !== 0) {
|
|
194
|
+
throw new RangeError('Buffer size must be a multiple of 64-bits')
|
|
195
|
+
}
|
|
174
196
|
|
|
175
197
|
for (let i = 0; i < length; i += 8) {
|
|
176
198
|
swap(this, i, i + 7)
|
|
@@ -182,7 +204,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
182
204
|
return this
|
|
183
205
|
}
|
|
184
206
|
|
|
185
|
-
toString
|
|
207
|
+
toString(encoding, start = 0, end = this.byteLength) {
|
|
186
208
|
// toString()
|
|
187
209
|
if (arguments.length === 0) return utf8.toString(this)
|
|
188
210
|
|
|
@@ -197,12 +219,19 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
197
219
|
|
|
198
220
|
let buffer = this
|
|
199
221
|
|
|
200
|
-
if (start !== 0 || end !== this.byteLength)
|
|
222
|
+
if (start !== 0 || end !== this.byteLength) {
|
|
223
|
+
buffer = buffer.subarray(start, end)
|
|
224
|
+
}
|
|
201
225
|
|
|
202
226
|
return codecFor(encoding).toString(buffer)
|
|
203
227
|
}
|
|
204
228
|
|
|
205
|
-
write
|
|
229
|
+
write(
|
|
230
|
+
string,
|
|
231
|
+
offset = 0,
|
|
232
|
+
length = this.byteLength - offset,
|
|
233
|
+
encoding = 'utf8'
|
|
234
|
+
) {
|
|
206
235
|
// write(string)
|
|
207
236
|
if (arguments.length === 1) return utf8.write(this, string)
|
|
208
237
|
|
|
@@ -212,7 +241,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
212
241
|
offset = 0
|
|
213
242
|
length = this.byteLength
|
|
214
243
|
|
|
215
|
-
|
|
244
|
+
// write(string, offset, encoding)
|
|
216
245
|
} else if (typeof length === 'string') {
|
|
217
246
|
encoding = length
|
|
218
247
|
length = this.byteLength - offset
|
|
@@ -230,91 +259,213 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
230
259
|
|
|
231
260
|
let buffer = this
|
|
232
261
|
|
|
233
|
-
if (start !== 0 || end !== this.byteLength)
|
|
262
|
+
if (start !== 0 || end !== this.byteLength) {
|
|
263
|
+
buffer = buffer.subarray(start, end)
|
|
264
|
+
}
|
|
234
265
|
|
|
235
266
|
return codecFor(encoding).write(buffer, string)
|
|
236
267
|
}
|
|
237
268
|
|
|
238
|
-
readBigInt64BE
|
|
239
|
-
|
|
269
|
+
readBigInt64BE(offset = 0) {
|
|
270
|
+
return viewOf(this).getBigInt64(offset, false)
|
|
271
|
+
}
|
|
272
|
+
readBigInt64LE(offset = 0) {
|
|
273
|
+
return viewOf(this).getBigInt64(offset, true)
|
|
274
|
+
}
|
|
240
275
|
|
|
241
|
-
readBigUint64BE
|
|
242
|
-
|
|
276
|
+
readBigUint64BE(offset = 0) {
|
|
277
|
+
return viewOf(this).getBigUint64(offset, false)
|
|
278
|
+
}
|
|
279
|
+
readBigUint64LE(offset = 0) {
|
|
280
|
+
return viewOf(this).getBigUint64(offset, true)
|
|
281
|
+
}
|
|
243
282
|
|
|
244
|
-
readDoubleBE
|
|
245
|
-
|
|
283
|
+
readDoubleBE(offset = 0) {
|
|
284
|
+
return viewOf(this).getFloat64(offset, false)
|
|
285
|
+
}
|
|
286
|
+
readDoubleLE(offset = 0) {
|
|
287
|
+
return viewOf(this).getFloat64(offset, true)
|
|
288
|
+
}
|
|
246
289
|
|
|
247
|
-
readFloatBE
|
|
248
|
-
|
|
290
|
+
readFloatBE(offset = 0) {
|
|
291
|
+
return viewOf(this).getFloat32(offset, false)
|
|
292
|
+
}
|
|
293
|
+
readFloatLE(offset = 0) {
|
|
294
|
+
return viewOf(this).getFloat32(offset, true)
|
|
295
|
+
}
|
|
249
296
|
|
|
250
|
-
readInt8
|
|
297
|
+
readInt8(offset = 0) {
|
|
298
|
+
return viewOf(this).getInt8(offset)
|
|
299
|
+
}
|
|
251
300
|
|
|
252
|
-
readInt16BE
|
|
253
|
-
|
|
301
|
+
readInt16BE(offset = 0) {
|
|
302
|
+
return viewOf(this).getInt16(offset, false)
|
|
303
|
+
}
|
|
304
|
+
readInt16LE(offset = 0) {
|
|
305
|
+
return viewOf(this).getInt16(offset, true)
|
|
306
|
+
}
|
|
254
307
|
|
|
255
|
-
readInt32BE
|
|
256
|
-
|
|
308
|
+
readInt32BE(offset = 0) {
|
|
309
|
+
return viewOf(this).getInt32(offset, false)
|
|
310
|
+
}
|
|
311
|
+
readInt32LE(offset = 0) {
|
|
312
|
+
return viewOf(this).getInt32(offset, true)
|
|
313
|
+
}
|
|
257
314
|
|
|
258
|
-
readUint8
|
|
315
|
+
readUint8(offset = 0) {
|
|
316
|
+
return viewOf(this).getUint8(offset)
|
|
317
|
+
}
|
|
259
318
|
|
|
260
|
-
readUint16BE
|
|
261
|
-
|
|
319
|
+
readUint16BE(offset = 0) {
|
|
320
|
+
return viewOf(this).getUint16(offset, false)
|
|
321
|
+
}
|
|
322
|
+
readUint16LE(offset = 0) {
|
|
323
|
+
return viewOf(this).getUint16(offset, true)
|
|
324
|
+
}
|
|
262
325
|
|
|
263
|
-
readUint32BE
|
|
264
|
-
|
|
326
|
+
readUint32BE(offset = 0) {
|
|
327
|
+
return viewOf(this).getUint32(offset, false)
|
|
328
|
+
}
|
|
329
|
+
readUint32LE(offset = 0) {
|
|
330
|
+
return viewOf(this).getUint32(offset, true)
|
|
331
|
+
}
|
|
265
332
|
|
|
266
|
-
readBigUInt64BE
|
|
267
|
-
|
|
333
|
+
readBigUInt64BE(...args) {
|
|
334
|
+
return this.readBigUint64BE(...args)
|
|
335
|
+
}
|
|
336
|
+
readBigUInt64LE(...args) {
|
|
337
|
+
return this.readBigUint64LE(...args)
|
|
338
|
+
}
|
|
268
339
|
|
|
269
|
-
readUInt8
|
|
340
|
+
readUInt8(...args) {
|
|
341
|
+
return this.readUint8(...args)
|
|
342
|
+
}
|
|
270
343
|
|
|
271
|
-
readUInt16BE
|
|
272
|
-
|
|
344
|
+
readUInt16BE(...args) {
|
|
345
|
+
return this.readUint16BE(...args)
|
|
346
|
+
}
|
|
347
|
+
readUInt16LE(...args) {
|
|
348
|
+
return this.readUint16LE(...args)
|
|
349
|
+
}
|
|
273
350
|
|
|
274
|
-
readUInt32BE
|
|
275
|
-
|
|
351
|
+
readUInt32BE(...args) {
|
|
352
|
+
return this.readUint32BE(...args)
|
|
353
|
+
}
|
|
354
|
+
readUInt32LE(...args) {
|
|
355
|
+
return this.readUint32LE(...args)
|
|
356
|
+
}
|
|
276
357
|
|
|
277
|
-
writeBigInt64BE
|
|
278
|
-
|
|
358
|
+
writeBigInt64BE(value, offset = 0) {
|
|
359
|
+
viewOf(this).setBigInt64(offset, value, false)
|
|
360
|
+
return offset + 8
|
|
361
|
+
}
|
|
362
|
+
writeBigInt64LE(value, offset = 0) {
|
|
363
|
+
viewOf(this).setBigInt64(offset, value, true)
|
|
364
|
+
return offset + 8
|
|
365
|
+
}
|
|
279
366
|
|
|
280
|
-
writeBigUint64BE
|
|
281
|
-
|
|
367
|
+
writeBigUint64BE(value, offset = 0) {
|
|
368
|
+
viewOf(this).setBigUint64(offset, value, false)
|
|
369
|
+
return offset + 8
|
|
370
|
+
}
|
|
371
|
+
writeBigUint64LE(value, offset = 0) {
|
|
372
|
+
viewOf(this).setBigUint64(offset, value, true)
|
|
373
|
+
return offset + 8
|
|
374
|
+
}
|
|
282
375
|
|
|
283
|
-
writeDoubleBE
|
|
284
|
-
|
|
376
|
+
writeDoubleBE(value, offset = 0) {
|
|
377
|
+
viewOf(this).setFloat64(offset, value, false)
|
|
378
|
+
return offset + 8
|
|
379
|
+
}
|
|
380
|
+
writeDoubleLE(value, offset = 0) {
|
|
381
|
+
viewOf(this).setFloat64(offset, value, true)
|
|
382
|
+
return offset + 8
|
|
383
|
+
}
|
|
285
384
|
|
|
286
|
-
writeFloatBE
|
|
287
|
-
|
|
385
|
+
writeFloatBE(value, offset = 0) {
|
|
386
|
+
viewOf(this).setFloat32(offset, value, false)
|
|
387
|
+
return offset + 4
|
|
388
|
+
}
|
|
389
|
+
writeFloatLE(value, offset = 0) {
|
|
390
|
+
viewOf(this).setFloat32(offset, value, true)
|
|
391
|
+
return offset + 4
|
|
392
|
+
}
|
|
288
393
|
|
|
289
|
-
writeInt8
|
|
394
|
+
writeInt8(value, offset = 0) {
|
|
395
|
+
viewOf(this).setInt8(offset, value)
|
|
396
|
+
return offset + 1
|
|
397
|
+
}
|
|
290
398
|
|
|
291
|
-
writeInt16BE
|
|
292
|
-
|
|
399
|
+
writeInt16BE(value, offset = 0) {
|
|
400
|
+
viewOf(this).setInt16(offset, value, false)
|
|
401
|
+
return offset + 2
|
|
402
|
+
}
|
|
403
|
+
writeInt16LE(value, offset = 0) {
|
|
404
|
+
viewOf(this).setInt16(offset, value, true)
|
|
405
|
+
return offset + 2
|
|
406
|
+
}
|
|
293
407
|
|
|
294
|
-
writeInt32BE
|
|
295
|
-
|
|
408
|
+
writeInt32BE(value, offset = 0) {
|
|
409
|
+
viewOf(this).setInt32(offset, value, false)
|
|
410
|
+
return offset + 4
|
|
411
|
+
}
|
|
412
|
+
writeInt32LE(value, offset = 0) {
|
|
413
|
+
viewOf(this).setInt32(offset, value, true)
|
|
414
|
+
return offset + 4
|
|
415
|
+
}
|
|
296
416
|
|
|
297
|
-
writeUint8
|
|
417
|
+
writeUint8(value, offset = 0) {
|
|
418
|
+
viewOf(this).setUint8(offset, value, true)
|
|
419
|
+
return offset + 1
|
|
420
|
+
}
|
|
298
421
|
|
|
299
|
-
writeUint16BE
|
|
300
|
-
|
|
422
|
+
writeUint16BE(value, offset = 0) {
|
|
423
|
+
viewOf(this).setUint16(offset, value, false)
|
|
424
|
+
return offset + 2
|
|
425
|
+
}
|
|
426
|
+
writeUint16LE(value, offset = 0) {
|
|
427
|
+
viewOf(this).setUint16(offset, value, true)
|
|
428
|
+
return offset + 2
|
|
429
|
+
}
|
|
301
430
|
|
|
302
|
-
writeUint32LE
|
|
303
|
-
|
|
431
|
+
writeUint32LE(value, offset = 0) {
|
|
432
|
+
viewOf(this).setUint32(offset, value, true)
|
|
433
|
+
return offset + 4
|
|
434
|
+
}
|
|
435
|
+
writeUint32BE(value, offset = 0) {
|
|
436
|
+
viewOf(this).setUint32(offset, value, false)
|
|
437
|
+
return offset + 4
|
|
438
|
+
}
|
|
304
439
|
|
|
305
|
-
writeBigUInt64BE
|
|
306
|
-
|
|
440
|
+
writeBigUInt64BE(...args) {
|
|
441
|
+
return this.writeBigUint64BE(...args)
|
|
442
|
+
}
|
|
443
|
+
writeBigUInt64LE(...args) {
|
|
444
|
+
return this.writeBigUint64LE(...args)
|
|
445
|
+
}
|
|
307
446
|
|
|
308
|
-
writeUInt8
|
|
447
|
+
writeUInt8(...args) {
|
|
448
|
+
return this.writeUint8(...args)
|
|
449
|
+
}
|
|
309
450
|
|
|
310
|
-
writeUInt16BE
|
|
311
|
-
|
|
451
|
+
writeUInt16BE(...args) {
|
|
452
|
+
return this.writeUint16BE(...args)
|
|
453
|
+
}
|
|
454
|
+
writeUInt16LE(...args) {
|
|
455
|
+
return this.writeUint16LE(...args)
|
|
456
|
+
}
|
|
312
457
|
|
|
313
|
-
writeUInt32BE
|
|
314
|
-
|
|
458
|
+
writeUInt32BE(...args) {
|
|
459
|
+
return this.writeUint32BE(...args)
|
|
460
|
+
}
|
|
461
|
+
writeUInt32LE(...args) {
|
|
462
|
+
return this.writeUint32LE(...args)
|
|
463
|
+
}
|
|
315
464
|
}
|
|
316
465
|
|
|
317
|
-
|
|
466
|
+
const Buffer = exports
|
|
467
|
+
|
|
468
|
+
exports.Buffer = Buffer // For Node.js compatibility
|
|
318
469
|
|
|
319
470
|
exports.constants = constants
|
|
320
471
|
|
|
@@ -326,7 +477,7 @@ codecs.hex = hex
|
|
|
326
477
|
codecs.utf8 = codecs['utf-8'] = utf8
|
|
327
478
|
codecs.utf16le = codecs.ucs2 = codecs['utf-16le'] = codecs['ucs-2'] = utf16le
|
|
328
479
|
|
|
329
|
-
function codecFor
|
|
480
|
+
function codecFor(encoding = 'utf8') {
|
|
330
481
|
if (encoding in codecs) return codecs[encoding]
|
|
331
482
|
|
|
332
483
|
encoding = encoding.toLowerCase()
|
|
@@ -338,7 +489,7 @@ function codecFor (encoding = 'utf8') {
|
|
|
338
489
|
|
|
339
490
|
const views = new WeakMap()
|
|
340
491
|
|
|
341
|
-
function viewOf
|
|
492
|
+
function viewOf(buffer) {
|
|
342
493
|
let view = views.get(buffer)
|
|
343
494
|
if (view === undefined) {
|
|
344
495
|
view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
@@ -347,7 +498,7 @@ function viewOf (buffer) {
|
|
|
347
498
|
return view
|
|
348
499
|
}
|
|
349
500
|
|
|
350
|
-
exports.isBuffer = function isBuffer
|
|
501
|
+
exports.isBuffer = function isBuffer(value) {
|
|
351
502
|
if (typeof value !== 'object' || value === null) return false
|
|
352
503
|
|
|
353
504
|
let constructor = value.constructor
|
|
@@ -361,7 +512,7 @@ exports.isBuffer = function isBuffer (value) {
|
|
|
361
512
|
return false
|
|
362
513
|
}
|
|
363
514
|
|
|
364
|
-
exports.isEncoding = function isEncoding
|
|
515
|
+
exports.isEncoding = function isEncoding(encoding) {
|
|
365
516
|
try {
|
|
366
517
|
codecFor(encoding)
|
|
367
518
|
return true
|
|
@@ -370,13 +521,13 @@ exports.isEncoding = function isEncoding (encoding) {
|
|
|
370
521
|
}
|
|
371
522
|
}
|
|
372
523
|
|
|
373
|
-
exports.alloc = function alloc
|
|
524
|
+
exports.alloc = function alloc(size, fill, encoding) {
|
|
374
525
|
const buffer = new Buffer(size)
|
|
375
526
|
if (fill !== undefined) buffer.fill(fill, 0, buffer.byteLength, encoding)
|
|
376
527
|
return buffer
|
|
377
528
|
}
|
|
378
529
|
|
|
379
|
-
exports.allocUnsafe = function allocUnsafe
|
|
530
|
+
exports.allocUnsafe = function allocUnsafe(size) {
|
|
380
531
|
binding.setZeroFillEnabled(0)
|
|
381
532
|
try {
|
|
382
533
|
return new Buffer(size)
|
|
@@ -385,11 +536,11 @@ exports.allocUnsafe = function allocUnsafe (size) {
|
|
|
385
536
|
}
|
|
386
537
|
}
|
|
387
538
|
|
|
388
|
-
exports.allocUnsafeSlow = function allocUnsafeSlow
|
|
539
|
+
exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
|
|
389
540
|
return exports.allocUnsafe(size)
|
|
390
541
|
}
|
|
391
542
|
|
|
392
|
-
exports.byteLength = function byteLength
|
|
543
|
+
exports.byteLength = function byteLength(string, encoding) {
|
|
393
544
|
if (typeof string === 'string') {
|
|
394
545
|
return codecFor(encoding).byteLength(string)
|
|
395
546
|
}
|
|
@@ -397,11 +548,11 @@ exports.byteLength = function byteLength (string, encoding) {
|
|
|
397
548
|
return string.byteLength
|
|
398
549
|
}
|
|
399
550
|
|
|
400
|
-
exports.compare = function compare
|
|
551
|
+
exports.compare = function compare(a, b) {
|
|
401
552
|
return binding.compare(a, b)
|
|
402
553
|
}
|
|
403
554
|
|
|
404
|
-
exports.concat = function concat
|
|
555
|
+
exports.concat = function concat(buffers, length) {
|
|
405
556
|
if (length === undefined) {
|
|
406
557
|
length = buffers.reduce((length, buffer) => length + buffer.byteLength, 0)
|
|
407
558
|
}
|
|
@@ -424,12 +575,12 @@ exports.concat = function concat (buffers, length) {
|
|
|
424
575
|
return result
|
|
425
576
|
}
|
|
426
577
|
|
|
427
|
-
exports.coerce = function coerce
|
|
578
|
+
exports.coerce = function coerce(buffer) {
|
|
428
579
|
if (exports.isBuffer(buffer)) return buffer
|
|
429
580
|
return new Buffer(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
430
581
|
}
|
|
431
582
|
|
|
432
|
-
exports.from = function from
|
|
583
|
+
exports.from = function from(value, encodingOrOffset, length) {
|
|
433
584
|
// from(string, encoding)
|
|
434
585
|
if (typeof value === 'string') return fromString(value, encodingOrOffset)
|
|
435
586
|
|
|
@@ -443,37 +594,37 @@ exports.from = function from (value, encodingOrOffset, length) {
|
|
|
443
594
|
return fromArrayBuffer(value, encodingOrOffset, length)
|
|
444
595
|
}
|
|
445
596
|
|
|
446
|
-
function fromString
|
|
597
|
+
function fromString(string, encoding) {
|
|
447
598
|
const codec = codecFor(encoding)
|
|
448
599
|
const buffer = new Buffer(codec.byteLength(string))
|
|
449
600
|
codec.write(buffer, string)
|
|
450
601
|
return buffer
|
|
451
602
|
}
|
|
452
603
|
|
|
453
|
-
function fromArray
|
|
604
|
+
function fromArray(array) {
|
|
454
605
|
const buffer = new Buffer(array.length)
|
|
455
606
|
buffer.set(array)
|
|
456
607
|
return buffer
|
|
457
608
|
}
|
|
458
609
|
|
|
459
|
-
function fromBuffer
|
|
610
|
+
function fromBuffer(buffer) {
|
|
460
611
|
const copy = new Buffer(buffer.byteLength)
|
|
461
612
|
copy.set(buffer)
|
|
462
613
|
return copy
|
|
463
614
|
}
|
|
464
615
|
|
|
465
|
-
function fromArrayBuffer
|
|
616
|
+
function fromArrayBuffer(arrayBuffer, offset, length) {
|
|
466
617
|
return new Buffer(arrayBuffer, offset, length)
|
|
467
618
|
}
|
|
468
619
|
|
|
469
|
-
function bidirectionalIndexOf
|
|
620
|
+
function bidirectionalIndexOf(buffer, value, offset, encoding, first) {
|
|
470
621
|
if (buffer.byteLength === 0) return -1
|
|
471
622
|
|
|
472
623
|
if (typeof offset === 'string') {
|
|
473
624
|
encoding = offset
|
|
474
625
|
offset = 0
|
|
475
626
|
} else if (offset === undefined) {
|
|
476
|
-
offset = first ? 0 :
|
|
627
|
+
offset = first ? 0 : buffer.byteLength - 1
|
|
477
628
|
} else if (offset < 0) {
|
|
478
629
|
offset += buffer.byteLength
|
|
479
630
|
}
|
|
@@ -524,7 +675,7 @@ function bidirectionalIndexOf (buffer, value, offset, encoding, first) {
|
|
|
524
675
|
return -1
|
|
525
676
|
}
|
|
526
677
|
|
|
527
|
-
function swap
|
|
678
|
+
function swap(buffer, n, m) {
|
|
528
679
|
const i = buffer[n]
|
|
529
680
|
buffer[n] = buffer[m]
|
|
530
681
|
buffer[m] = i
|
package/lib/ascii.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
exports.byteLength = function byteLength
|
|
1
|
+
exports.byteLength = function byteLength(string) {
|
|
2
2
|
return string.length
|
|
3
3
|
}
|
|
4
4
|
|
|
5
|
-
exports.toString = function toString
|
|
5
|
+
exports.toString = function toString(buffer) {
|
|
6
6
|
const len = buffer.byteLength
|
|
7
7
|
|
|
8
8
|
let result = ''
|
|
@@ -14,7 +14,7 @@ exports.toString = function toString (buffer) {
|
|
|
14
14
|
return result
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
exports.write = function write
|
|
17
|
+
exports.write = function write(buffer, string) {
|
|
18
18
|
const len = buffer.byteLength
|
|
19
19
|
|
|
20
20
|
for (let i = 0; i < len; i++) {
|
package/lib/base64.js
CHANGED
package/lib/hex.js
CHANGED
package/lib/utf16le.js
CHANGED
package/package.json
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bare-buffer",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Native buffers for JavaScript",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": "./index.js",
|
|
7
7
|
"./package": "./package.json",
|
|
8
|
+
"./global": "./global.js",
|
|
8
9
|
"./constants": "./lib/constants.js"
|
|
9
10
|
},
|
|
10
11
|
"files": [
|
|
11
12
|
"index.js",
|
|
13
|
+
"global.js",
|
|
12
14
|
"binding.c",
|
|
13
15
|
"binding.js",
|
|
14
16
|
"CMakeLists.txt",
|
|
@@ -17,7 +19,7 @@
|
|
|
17
19
|
],
|
|
18
20
|
"addon": true,
|
|
19
21
|
"scripts": {
|
|
20
|
-
"test": "
|
|
22
|
+
"test": "prettier . --check && bare test/all.js"
|
|
21
23
|
},
|
|
22
24
|
"repository": {
|
|
23
25
|
"type": "git",
|
|
@@ -33,6 +35,7 @@
|
|
|
33
35
|
"brittle": "^3.1.1",
|
|
34
36
|
"cmake-bare": "^1.1.6",
|
|
35
37
|
"cmake-fetch": "^1.0.0",
|
|
36
|
-
"
|
|
38
|
+
"prettier": "^3.3.3",
|
|
39
|
+
"prettier-config-standard": "^7.0.0"
|
|
37
40
|
}
|
|
38
41
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|