bare-buffer 1.2.8 → 1.2.10
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/binding.c +11 -1
- package/index.js +5 -6
- package/lib/base64.js +2 -6
- package/lib/hex.js +2 -6
- package/lib/utf16le.js +2 -6
- package/lib/utf8.js +3 -9
- package/package.json +1 -1
package/binding.c
CHANGED
|
@@ -36,7 +36,17 @@ bare_buffer_set_zero_fill_enabled (js_env_t *env, js_callback_info_t *info) {
|
|
|
36
36
|
|
|
37
37
|
static uint32_t
|
|
38
38
|
bare_buffer_byte_length_utf8_fast (js_ffi_receiver_t *receiver, js_ffi_string_t *str) {
|
|
39
|
-
|
|
39
|
+
const uint8_t *data = (const uint8_t *) str->data;
|
|
40
|
+
|
|
41
|
+
uint32_t len = 0;
|
|
42
|
+
|
|
43
|
+
for (uint32_t i = 0, n = str->len; i < n; i++) {
|
|
44
|
+
// The string data is latin1 so we add an additional byte count for all
|
|
45
|
+
// non-ASCII characters.
|
|
46
|
+
len += 1 + (data[i] >> 7);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return len;
|
|
40
50
|
}
|
|
41
51
|
|
|
42
52
|
static js_value_t *
|
package/index.js
CHANGED
|
@@ -118,17 +118,13 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
indexOf (value, offset = 0, encoding) {
|
|
121
|
-
if (typeof value === 'number')
|
|
122
|
-
return super.indexOf(value & 0xff, offset)
|
|
123
|
-
}
|
|
121
|
+
if (typeof value === 'number') return super.indexOf(value & 0xff, offset)
|
|
124
122
|
|
|
125
123
|
return bidirectionalIndexOf(this, value, offset, encoding, true /* first */)
|
|
126
124
|
}
|
|
127
125
|
|
|
128
126
|
lastIndexOf (value, offset = this.byteLength - 1, encoding) {
|
|
129
|
-
if (typeof value === 'number')
|
|
130
|
-
return super.lastIndexOf(value & 0xff, offset)
|
|
131
|
-
}
|
|
127
|
+
if (typeof value === 'number') return super.lastIndexOf(value & 0xff, offset)
|
|
132
128
|
|
|
133
129
|
return bidirectionalIndexOf(this, value, offset, encoding, false /* last */)
|
|
134
130
|
}
|
|
@@ -172,8 +168,10 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
172
168
|
}
|
|
173
169
|
|
|
174
170
|
toString (encoding, start = 0, end = this.byteLength) {
|
|
171
|
+
// toString()
|
|
175
172
|
if (arguments.length === 0) return utf8.toString(this)
|
|
176
173
|
|
|
174
|
+
// toString(encoding)
|
|
177
175
|
if (arguments.length === 1) return codecFor(encoding).toString(this)
|
|
178
176
|
|
|
179
177
|
if (start < 0) start = 0
|
|
@@ -190,6 +188,7 @@ const Buffer = module.exports = exports = class Buffer extends Uint8Array {
|
|
|
190
188
|
}
|
|
191
189
|
|
|
192
190
|
write (string, offset = 0, length = this.byteLength - offset, encoding = 'utf8') {
|
|
191
|
+
// write(string)
|
|
193
192
|
if (arguments.length === 1) return utf8.write(this, string)
|
|
194
193
|
|
|
195
194
|
// write(string, encoding)
|
package/lib/base64.js
CHANGED
|
@@ -9,10 +9,6 @@ exports.byteLength = function byteLength (string) {
|
|
|
9
9
|
return (len * 3) >>> 2
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
exports.toString =
|
|
13
|
-
return binding.toStringBase64(buffer)
|
|
14
|
-
}
|
|
12
|
+
exports.toString = binding.toStringBase64
|
|
15
13
|
|
|
16
|
-
exports.write =
|
|
17
|
-
return binding.writeBase64(buffer, string)
|
|
18
|
-
}
|
|
14
|
+
exports.write = binding.writeBase64
|
package/lib/hex.js
CHANGED
|
@@ -4,10 +4,6 @@ exports.byteLength = function byteLength (string) {
|
|
|
4
4
|
return string.length >>> 1
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
exports.toString =
|
|
8
|
-
return binding.toStringHex(buffer)
|
|
9
|
-
}
|
|
7
|
+
exports.toString = binding.toStringHex
|
|
10
8
|
|
|
11
|
-
exports.write =
|
|
12
|
-
return binding.writeHex(buffer, string)
|
|
13
|
-
}
|
|
9
|
+
exports.write = binding.writeHex
|
package/lib/utf16le.js
CHANGED
|
@@ -4,10 +4,6 @@ exports.byteLength = function byteLength (string) {
|
|
|
4
4
|
return string.length * 2
|
|
5
5
|
}
|
|
6
6
|
|
|
7
|
-
exports.toString =
|
|
8
|
-
return binding.toStringUTF16LE(buffer)
|
|
9
|
-
}
|
|
7
|
+
exports.toString = binding.toStringUTF16LE
|
|
10
8
|
|
|
11
|
-
exports.write =
|
|
12
|
-
return binding.writeUTF16LE(buffer, string)
|
|
13
|
-
}
|
|
9
|
+
exports.write = binding.writeUTF16LE
|
package/lib/utf8.js
CHANGED
|
@@ -1,13 +1,7 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
2
|
|
|
3
|
-
exports.byteLength =
|
|
4
|
-
return binding.byteLengthUTF8(string)
|
|
5
|
-
}
|
|
3
|
+
exports.byteLength = binding.byteLengthUTF8
|
|
6
4
|
|
|
7
|
-
exports.toString =
|
|
8
|
-
return binding.toStringUTF8(buffer)
|
|
9
|
-
}
|
|
5
|
+
exports.toString = binding.toStringUTF8
|
|
10
6
|
|
|
11
|
-
exports.write =
|
|
12
|
-
return binding.writeUTF8(buffer, string)
|
|
13
|
-
}
|
|
7
|
+
exports.write = binding.writeUTF8
|