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 CHANGED
@@ -20,9 +20,11 @@ target_sources(
20
20
  target_link_libraries(
21
21
  ${bare_buffer}
22
22
  PRIVATE
23
+ $<TARGET_OBJECTS:utf>
23
24
  $<TARGET_OBJECTS:base64>
24
25
  $<TARGET_OBJECTS:hex>
25
26
  PUBLIC
27
+ utf
26
28
  base64
27
29
  hex
28
30
  )
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
- const uint8_t *data = (const uint8_t *) str->data;
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
- const Buffer = module.exports = exports = class Buffer extends Uint8Array {
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
- [Symbol.species] () {
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 (target, targetStart = 0, sourceStart = 0, sourceEnd = this.byteLength) {
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) 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) source = source.subarray(sourceStart, sourceEnd)
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 (target) {
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 (target, targetStart = 0, targetEnd = target.byteLength, sourceStart = 0, sourceEnd = this.byteLength) {
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) source = source.subarray(sourceStart, sourceEnd)
96
+ if (sourceStart !== 0 || sourceEnd !== source.byteLength) {
97
+ source = source.subarray(sourceStart, sourceEnd)
98
+ }
77
99
 
78
- if (targetStart !== 0 || targetEnd !== target.byteLength) target = target.subarray(targetStart, targetEnd)
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 (value, offset = 0, end = this.byteLength, encoding = 'utf8') {
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
- // fill(string, offset, encoding)
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 (value, offset, encoding) {
145
+ includes(value, offset, encoding) {
122
146
  return this.indexOf(value, offset, encoding) !== -1
123
147
  }
124
148
 
125
- indexOf (value, offset = 0, encoding) {
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 (value, offset = this.byteLength - 1, encoding) {
132
- if (typeof value === 'number') return super.lastIndexOf(value & 0xff, offset)
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) throw new RangeError('Buffer size must be a multiple of 16-bits')
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) throw new RangeError('Buffer size must be a multiple of 32-bits')
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) throw new RangeError('Buffer size must be a multiple of 64-bits')
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 (encoding, start = 0, end = this.byteLength) {
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) buffer = buffer.subarray(start, end)
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 (string, offset = 0, length = this.byteLength - offset, encoding = 'utf8') {
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
- // write(string, offset, encoding)
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) buffer = buffer.subarray(start, end)
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
- writeUInt8 (value, offset = 0) {
229
- const view = new DataView(this.buffer, this.byteoffset, this.bytelength)
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
- writeUint8 (...args) {
236
- return this.writeUInt8(...args)
272
+ readBigInt64LE(offset = 0) {
273
+ return viewOf(this).getBigInt64(offset, true)
237
274
  }
238
275
 
239
- writeInt8 (value, offset = 0) {
240
- const view = new DataView(this.buffer, this.byteoffset, this.bytelength)
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
- writeDoubleLE (value, offset = 0) {
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
- writeFloatLE (value, offset = 0) {
254
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
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
- writeUInt16LE (value, offset = 0) {
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
- writeUInt32LE (value, offset = 0) {
268
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
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
- writeInt32LE (value, offset = 0) {
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 (offset = 0) {
282
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
283
-
284
- return view.getInt8(offset)
297
+ readInt8(offset = 0) {
298
+ return viewOf(this).getInt8(offset)
285
299
  }
286
300
 
287
- readUInt8 (offset = 0) {
288
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
289
-
290
- return view.getUint8(offset)
301
+ readInt16BE(offset = 0) {
302
+ return viewOf(this).getInt16(offset, false)
291
303
  }
292
-
293
- readUint8 (...args) {
294
- return this.readUInt8(...args)
304
+ readInt16LE(offset = 0) {
305
+ return viewOf(this).getInt16(offset, true)
295
306
  }
296
307
 
297
- readDoubleLE (offset = 0) {
298
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
299
-
300
- return view.getFloat64(offset, true)
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
- readFloatLE (offset = 0) {
304
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
305
-
306
- return view.getFloat32(offset, true)
315
+ readUint8(offset = 0) {
316
+ return viewOf(this).getUint8(offset)
307
317
  }
308
318
 
309
- readUInt16LE (offset = 0) {
310
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
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
- return view.getUint16(offset, true)
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
- readUInt32LE (offset = 0) {
316
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
333
+ readBigUInt64BE(...args) {
334
+ return this.readBigUint64BE(...args)
335
+ }
336
+ readBigUInt64LE(...args) {
337
+ return this.readBigUint64LE(...args)
338
+ }
317
339
 
318
- return view.getUint32(offset, true)
340
+ readUInt8(...args) {
341
+ return this.readUint8(...args)
319
342
  }
320
343
 
321
- readInt32LE (offset = 0) {
322
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
344
+ readUInt16BE(...args) {
345
+ return this.readUint16BE(...args)
346
+ }
347
+ readUInt16LE(...args) {
348
+ return this.readUint16LE(...args)
349
+ }
323
350
 
324
- return view.getInt32(offset, true)
351
+ readUInt32BE(...args) {
352
+ return this.readUint32BE(...args)
353
+ }
354
+ readUInt32LE(...args) {
355
+ return this.readUint32LE(...args)
325
356
  }
326
357
 
327
- writeDoubleBE (value, offset = 0) {
328
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
329
- view.setFloat64(offset, value, false)
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
- writeFloatBE (value, offset = 0) {
335
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
336
- view.setFloat32(offset, value, false)
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
- writeUInt16BE (value, offset = 0) {
342
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
343
- view.setUint16(offset, value, false)
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
- writeUInt32BE (value, offset = 0) {
349
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
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
- writeInt32BE (value, offset = 0) {
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
- readDoubleBE (offset = 0) {
363
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
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
- readFloatBE (offset = 0) {
369
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
370
-
371
- return view.getFloat32(offset, false)
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
- readUInt16BE (offset = 0) {
375
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
376
-
377
- return view.getUint16(offset, false)
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
- readUInt32BE (offset = 0) {
381
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
440
+ writeBigUInt64BE(...args) {
441
+ return this.writeBigUint64BE(...args)
442
+ }
443
+ writeBigUInt64LE(...args) {
444
+ return this.writeBigUint64LE(...args)
445
+ }
382
446
 
383
- return view.getUint32(offset, false)
447
+ writeUInt8(...args) {
448
+ return this.writeUint8(...args)
384
449
  }
385
450
 
386
- readInt32BE (offset = 0) {
387
- const view = new DataView(this.buffer, this.byteOffset, this.byteLength)
451
+ writeUInt16BE(...args) {
452
+ return this.writeUint16BE(...args)
453
+ }
454
+ writeUInt16LE(...args) {
455
+ return this.writeUint16LE(...args)
456
+ }
388
457
 
389
- return view.getInt32(offset, false)
458
+ writeUInt32BE(...args) {
459
+ return this.writeUint32BE(...args)
460
+ }
461
+ writeUInt32LE(...args) {
462
+ return this.writeUint32LE(...args)
390
463
  }
391
464
  }
392
465
 
393
- exports.Buffer = exports
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 (encoding = 'utf8') {
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
- exports.isBuffer = function isBuffer (value) {
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 (encoding) {
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 (size, fill, encoding) {
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 (size) {
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 (size) {
539
+ exports.allocUnsafeSlow = function allocUnsafeSlow(size) {
454
540
  return exports.allocUnsafe(size)
455
541
  }
456
542
 
457
- exports.byteLength = function byteLength (string, encoding) {
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 (a, b) {
551
+ exports.compare = function compare(a, b) {
466
552
  return binding.compare(a, b)
467
553
  }
468
554
 
469
- exports.concat = function concat (buffers, length) {
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 (buffer) {
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 (value, encodingOrOffset, length) {
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 (string, encoding) {
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 (array) {
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 (buffer) {
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 (arrayBuffer, offset, length) {
616
+ function fromArrayBuffer(arrayBuffer, offset, length) {
531
617
  return new Buffer(arrayBuffer, offset, length)
532
618
  }
533
619
 
534
- function bidirectionalIndexOf (buffer, value, offset, encoding, first) {
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 : (buffer.byteLength - 1)
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 (buffer, n, m) {
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 (string) {
1
+ exports.byteLength = function byteLength(string) {
2
2
  return string.length
3
3
  }
4
4
 
5
- exports.toString = function toString (buffer) {
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 (buffer, string) {
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
@@ -1,6 +1,6 @@
1
1
  const binding = require('../binding')
2
2
 
3
- exports.byteLength = function byteLength (string) {
3
+ exports.byteLength = function byteLength(string) {
4
4
  let len = string.length
5
5
 
6
6
  if (string.charCodeAt(len - 1) === 0x3d) len--
package/lib/hex.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const binding = require('../binding')
2
2
 
3
- exports.byteLength = function byteLength (string) {
3
+ exports.byteLength = function byteLength(string) {
4
4
  return string.length >>> 1
5
5
  }
6
6
 
package/lib/utf16le.js CHANGED
@@ -1,6 +1,6 @@
1
1
  const binding = require('../binding')
2
2
 
3
- exports.byteLength = function byteLength (string) {
3
+ exports.byteLength = function byteLength(string) {
4
4
  return string.length * 2
5
5
  }
6
6
 
package/package.json CHANGED
@@ -1,14 +1,16 @@
1
1
  {
2
2
  "name": "bare-buffer",
3
- "version": "2.5.11",
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": "standard && bare test/all.js"
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
- "standard": "^17.0.0"
38
+ "prettier": "^3.3.3",
39
+ "prettier-config-standard": "^7.0.0"
37
40
  }
38
41
  }