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