bare-buffer 2.5.11 → 2.6.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/index.js +71 -136
- package/package.json +1 -1
- 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/index.js
CHANGED
|
@@ -6,11 +6,21 @@ const utf8 = require('./lib/utf8')
|
|
|
6
6
|
const utf16le = require('./lib/utf16le')
|
|
7
7
|
const binding = require('./binding')
|
|
8
8
|
|
|
9
|
+
let poolSize = 0
|
|
10
|
+
|
|
9
11
|
const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
10
12
|
static {
|
|
11
13
|
binding.tag(this)
|
|
12
14
|
}
|
|
13
15
|
|
|
16
|
+
static get poolSize () {
|
|
17
|
+
return poolSize
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
static set poolSize (value) {
|
|
21
|
+
poolSize = Math.max(0, value)
|
|
22
|
+
}
|
|
23
|
+
|
|
14
24
|
[Symbol.species] () {
|
|
15
25
|
return Buffer
|
|
16
26
|
}
|
|
@@ -225,169 +235,83 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
225
235
|
return codecFor(encoding).write(buffer, string)
|
|
226
236
|
}
|
|
227
237
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
view.setUint8(offset, value, true)
|
|
238
|
+
readBigInt64BE (offset = 0) { return viewOf(this).getBigInt64(offset, false) }
|
|
239
|
+
readBigInt64LE (offset = 0) { return viewOf(this).getBigInt64(offset, true) }
|
|
231
240
|
|
|
232
|
-
|
|
233
|
-
}
|
|
241
|
+
readBigUint64BE (offset = 0) { return viewOf(this).getBigUint64(offset, false) }
|
|
242
|
+
readBigUint64LE (offset = 0) { return viewOf(this).getBigUint64(offset, true) }
|
|
234
243
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
}
|
|
244
|
+
readDoubleBE (offset = 0) { return viewOf(this).getFloat64(offset, false) }
|
|
245
|
+
readDoubleLE (offset = 0) { return viewOf(this).getFloat64(offset, true) }
|
|
238
246
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
view.setInt8(offset, value)
|
|
247
|
+
readFloatBE (offset = 0) { return viewOf(this).getFloat32(offset, false) }
|
|
248
|
+
readFloatLE (offset = 0) { return viewOf(this).getFloat32(offset, true) }
|
|
242
249
|
|
|
243
|
-
|
|
244
|
-
}
|
|
250
|
+
readInt8 (offset = 0) { return viewOf(this).getInt8(offset) }
|
|
245
251
|
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
view.setFloat64(offset, value, true)
|
|
252
|
+
readInt16BE (offset = 0) { return viewOf(this).getInt16(offset, false) }
|
|
253
|
+
readInt16LE (offset = 0) { return viewOf(this).getInt16(offset, true) }
|
|
249
254
|
|
|
250
|
-
|
|
251
|
-
}
|
|
255
|
+
readInt32BE (offset = 0) { return viewOf(this).getInt32(offset, false) }
|
|
256
|
+
readInt32LE (offset = 0) { return viewOf(this).getInt32(offset, true) }
|
|
252
257
|
|
|
253
|
-
|
|
254
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
255
|
-
view.setFloat32(offset, value, true)
|
|
258
|
+
readUint8 (offset = 0) { return viewOf(this).getUint8(offset) }
|
|
256
259
|
|
|
257
|
-
|
|
258
|
-
}
|
|
260
|
+
readUint16BE (offset = 0) { return viewOf(this).getUint16(offset, false) }
|
|
261
|
+
readUint16LE (offset = 0) { return viewOf(this).getUint16(offset, true) }
|
|
259
262
|
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
view.setUint16(offset, value, true)
|
|
263
|
+
readUint32BE (offset = 0) { return viewOf(this).getUint32(offset, false) }
|
|
264
|
+
readUint32LE (offset = 0) { return viewOf(this).getUint32(offset, true) }
|
|
263
265
|
|
|
264
|
-
|
|
265
|
-
}
|
|
266
|
+
readBigUInt64BE (...args) { return this.readBigUint64BE(...args) }
|
|
267
|
+
readBigUInt64LE (...args) { return this.readBigUint64LE(...args) }
|
|
266
268
|
|
|
267
|
-
|
|
268
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
269
|
-
view.setUint32(offset, value, true)
|
|
269
|
+
readUInt8 (...args) { return this.readUint8(...args) }
|
|
270
270
|
|
|
271
|
-
|
|
272
|
-
}
|
|
271
|
+
readUInt16BE (...args) { return this.readUint16BE(...args) }
|
|
272
|
+
readUInt16LE (...args) { return this.readUint16LE(...args) }
|
|
273
273
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
view.setInt32(offset, value, true)
|
|
274
|
+
readUInt32BE (...args) { return this.readUint32BE(...args) }
|
|
275
|
+
readUInt32LE (...args) { return this.readUint32LE(...args) }
|
|
277
276
|
|
|
278
|
-
|
|
279
|
-
}
|
|
277
|
+
writeBigInt64BE (value, offset = 0) { viewOf(this).setBigInt64(offset, value, false); return offset + 8 }
|
|
278
|
+
writeBigInt64LE (value, offset = 0) { viewOf(this).setBigInt64(offset, value, true); return offset + 8 }
|
|
280
279
|
|
|
281
|
-
|
|
282
|
-
|
|
280
|
+
writeBigUint64BE (value, offset = 0) { viewOf(this).setBigUint64(offset, value, false); return offset + 8 }
|
|
281
|
+
writeBigUint64LE (value, offset = 0) { viewOf(this).setBigUint64(offset, value, true); return offset + 8 }
|
|
283
282
|
|
|
284
|
-
|
|
285
|
-
}
|
|
283
|
+
writeDoubleBE (value, offset = 0) { viewOf(this).setFloat64(offset, value, false); return offset + 8 }
|
|
284
|
+
writeDoubleLE (value, offset = 0) { viewOf(this).setFloat64(offset, value, true); return offset + 8 }
|
|
286
285
|
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
writeFloatBE (value, offset = 0) { viewOf(this).setFloat32(offset, value, false); return offset + 4 }
|
|
287
|
+
writeFloatLE (value, offset = 0) { viewOf(this).setFloat32(offset, value, true); return offset + 4 }
|
|
289
288
|
|
|
290
|
-
|
|
291
|
-
}
|
|
289
|
+
writeInt8 (value, offset = 0) { viewOf(this).setInt8(offset, value); return offset + 1 }
|
|
292
290
|
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
}
|
|
296
|
-
|
|
297
|
-
readDoubleLE (offset = 0) {
|
|
298
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
299
|
-
|
|
300
|
-
return view.getFloat64(offset, true)
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
readFloatLE (offset = 0) {
|
|
304
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
305
|
-
|
|
306
|
-
return view.getFloat32(offset, true)
|
|
307
|
-
}
|
|
291
|
+
writeInt16BE (value, offset = 0) { viewOf(this).setInt16(offset, value, false); return offset + 2 }
|
|
292
|
+
writeInt16LE (value, offset = 0) { viewOf(this).setInt16(offset, value, true); return offset + 2 }
|
|
308
293
|
|
|
309
|
-
|
|
310
|
-
|
|
294
|
+
writeInt32BE (value, offset = 0) { viewOf(this).setInt32(offset, value, false); return offset + 4 }
|
|
295
|
+
writeInt32LE (value, offset = 0) { viewOf(this).setInt32(offset, value, true); return offset + 4 }
|
|
311
296
|
|
|
312
|
-
|
|
313
|
-
}
|
|
297
|
+
writeUint8 (value, offset = 0) { viewOf(this).setUint8(offset, value, true); return offset + 1 }
|
|
314
298
|
|
|
315
|
-
|
|
316
|
-
|
|
299
|
+
writeUint16BE (value, offset = 0) { viewOf(this).setUint16(offset, value, false); return offset + 2 }
|
|
300
|
+
writeUint16LE (value, offset = 0) { viewOf(this).setUint16(offset, value, true); return offset + 2 }
|
|
317
301
|
|
|
318
|
-
|
|
319
|
-
}
|
|
302
|
+
writeUint32LE (value, offset = 0) { viewOf(this).setUint32(offset, value, true); return offset + 4 }
|
|
303
|
+
writeUint32BE (value, offset = 0) { viewOf(this).setUint32(offset, value, false); return offset + 4 }
|
|
320
304
|
|
|
321
|
-
|
|
322
|
-
|
|
305
|
+
writeBigUInt64BE (...args) { return this.writeBigUint64BE(...args) }
|
|
306
|
+
writeBigUInt64LE (...args) { return this.writeBigUint64LE(...args) }
|
|
323
307
|
|
|
324
|
-
|
|
325
|
-
}
|
|
308
|
+
writeUInt8 (...args) { return this.writeUint8(...args) }
|
|
326
309
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
view.setFloat64(offset, value, false)
|
|
310
|
+
writeUInt16BE (...args) { return this.writeUint16BE(...args) }
|
|
311
|
+
writeUInt16LE (...args) { return this.writeUint16LE(...args) }
|
|
330
312
|
|
|
331
|
-
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
writeFloatBE (value, offset = 0) {
|
|
335
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
336
|
-
view.setFloat32(offset, value, false)
|
|
337
|
-
|
|
338
|
-
return offset + 4
|
|
339
|
-
}
|
|
340
|
-
|
|
341
|
-
writeUInt16BE (value, offset = 0) {
|
|
342
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
343
|
-
view.setUint16(offset, value, false)
|
|
344
|
-
|
|
345
|
-
return offset + 2
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
writeUInt32BE (value, offset = 0) {
|
|
349
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
350
|
-
view.setUint32(offset, value, false)
|
|
351
|
-
|
|
352
|
-
return offset + 4
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
writeInt32BE (value, offset = 0) {
|
|
356
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
357
|
-
view.setInt32(offset, value, false)
|
|
358
|
-
|
|
359
|
-
return offset + 4
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
readDoubleBE (offset = 0) {
|
|
363
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
364
|
-
|
|
365
|
-
return view.getFloat64(offset, false)
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
readFloatBE (offset = 0) {
|
|
369
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
370
|
-
|
|
371
|
-
return view.getFloat32(offset, false)
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
readUInt16BE (offset = 0) {
|
|
375
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
376
|
-
|
|
377
|
-
return view.getUint16(offset, false)
|
|
378
|
-
}
|
|
379
|
-
|
|
380
|
-
readUInt32BE (offset = 0) {
|
|
381
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
382
|
-
|
|
383
|
-
return view.getUint32(offset, false)
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
readInt32BE (offset = 0) {
|
|
387
|
-
const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
|
|
388
|
-
|
|
389
|
-
return view.getInt32(offset, false)
|
|
390
|
-
}
|
|
313
|
+
writeUInt32BE (...args) { return this.writeUint32BE(...args) }
|
|
314
|
+
writeUInt32LE (...args) { return this.writeUint32LE(...args) }
|
|
391
315
|
}
|
|
392
316
|
|
|
393
317
|
exports.Buffer = exports
|
|
@@ -412,6 +336,17 @@ function codecFor (encoding = 'utf8') {
|
|
|
412
336
|
throw new Error(`Unknown encoding: ${encoding}`)
|
|
413
337
|
}
|
|
414
338
|
|
|
339
|
+
const views = new WeakMap()
|
|
340
|
+
|
|
341
|
+
function viewOf (buffer) {
|
|
342
|
+
let view = views.get(buffer)
|
|
343
|
+
if (view === undefined) {
|
|
344
|
+
view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength)
|
|
345
|
+
views.set(buffer, view)
|
|
346
|
+
}
|
|
347
|
+
return view
|
|
348
|
+
}
|
|
349
|
+
|
|
415
350
|
exports.isBuffer = function isBuffer (value) {
|
|
416
351
|
if (typeof value !== 'object' || value === null) return false
|
|
417
352
|
|
package/package.json
CHANGED
|
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
|