@ohos-ports/bare-buffer 3.7.1-beta.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/LICENSE +201 -0
- package/README.md +26 -0
- package/binding.c +1077 -0
- package/binding.gyp +32 -0
- package/binding.js +1 -0
- package/build/Release/bare_buffer.node +0 -0
- package/deps/libbase64/.clang-format +10 -0
- package/deps/libbase64/.gitattributes +1 -0
- package/deps/libbase64/.github/workflows/integrate.yml +45 -0
- package/deps/libbase64/.github/workflows/nightly.yml +28 -0
- package/deps/libbase64/.prettierrc +1 -0
- package/deps/libbase64/CMakeLists.txt +71 -0
- package/deps/libbase64/LICENSE +201 -0
- package/deps/libbase64/NOTICE +13 -0
- package/deps/libbase64/README.md +11 -0
- package/deps/libbase64/include/base64.h +323 -0
- package/deps/libbase64/package.json +25 -0
- package/deps/libbase64/src/base64.c +22 -0
- package/deps/libbase64/test/CMakeLists.txt +31 -0
- package/deps/libbase64/test/decode-invalid.c +35 -0
- package/deps/libbase64/test/decode-length.c +23 -0
- package/deps/libbase64/test/decode.c +36 -0
- package/deps/libbase64/test/encode-length.c +22 -0
- package/deps/libbase64/test/encode.c +42 -0
- package/deps/libbase64/test/fuzz/CMakeLists.txt +18 -0
- package/deps/libbase64/test/fuzz/decode/utf16le.c +53 -0
- package/deps/libbase64/test/fuzz/decode/utf8.c +47 -0
- package/deps/libbase64/test/fuzz/encode/utf16le.c +56 -0
- package/deps/libbase64/test/fuzz/encode/utf8.c +56 -0
- package/deps/libhex/.clang-format +10 -0
- package/deps/libhex/.gitattributes +1 -0
- package/deps/libhex/.github/workflows/integrate.yml +45 -0
- package/deps/libhex/.github/workflows/nightly.yml +28 -0
- package/deps/libhex/.prettierrc +1 -0
- package/deps/libhex/CMakeLists.txt +72 -0
- package/deps/libhex/LICENSE +201 -0
- package/deps/libhex/NOTICE +13 -0
- package/deps/libhex/README.md +11 -0
- package/deps/libhex/include/hex.h +163 -0
- package/deps/libhex/package.json +25 -0
- package/deps/libhex/src/hex.c +16 -0
- package/deps/libhex/test/CMakeLists.txt +31 -0
- package/deps/libhex/test/decode-invalid.c +37 -0
- package/deps/libhex/test/decode-length.c +23 -0
- package/deps/libhex/test/decode.c +25 -0
- package/deps/libhex/test/encode-length.c +22 -0
- package/deps/libhex/test/encode.c +25 -0
- package/deps/libhex/test/fuzz/CMakeLists.txt +18 -0
- package/deps/libhex/test/fuzz/decode/utf16le.c +53 -0
- package/deps/libhex/test/fuzz/decode/utf8.c +47 -0
- package/deps/libhex/test/fuzz/encode/utf16le.c +36 -0
- package/deps/libhex/test/fuzz/encode/utf8.c +36 -0
- package/deps/libutf/.clang-format +10 -0
- package/deps/libutf/.gitattributes +1 -0
- package/deps/libutf/.github/workflows/integrate.yml +45 -0
- package/deps/libutf/.github/workflows/nightly.yml +28 -0
- package/deps/libutf/.prettierrc +1 -0
- package/deps/libutf/CMakeLists.txt +105 -0
- package/deps/libutf/LICENSE +201 -0
- package/deps/libutf/NOTICE +13 -0
- package/deps/libutf/README.md +11 -0
- package/deps/libutf/include/utf/string.h +1655 -0
- package/deps/libutf/include/utf.h +132 -0
- package/deps/libutf/package.json +24 -0
- package/deps/libutf/src/ascii/validate.c +47 -0
- package/deps/libutf/src/endianness.c +19 -0
- package/deps/libutf/src/endianness.h +54 -0
- package/deps/libutf/src/latin1/convert-to-utf16.c +37 -0
- package/deps/libutf/src/latin1/convert-to-utf32.c +34 -0
- package/deps/libutf/src/latin1/convert-to-utf8.c +58 -0
- package/deps/libutf/src/latin1/length-from-utf16.c +26 -0
- package/deps/libutf/src/latin1/length-from-utf32.c +26 -0
- package/deps/libutf/src/latin1/length-from-utf8.c +34 -0
- package/deps/libutf/src/utf16/convert-to-latin1.c +41 -0
- package/deps/libutf/src/utf16/convert-to-utf32.c +56 -0
- package/deps/libutf/src/utf16/convert-to-utf8.c +80 -0
- package/deps/libutf/src/utf16/length-from-latin1.c +26 -0
- package/deps/libutf/src/utf16/length-from-utf32.c +33 -0
- package/deps/libutf/src/utf16/length-from-utf8.c +38 -0
- package/deps/libutf/src/utf16/validate.c +53 -0
- package/deps/libutf/src/utf32/convert-to-latin1.c +40 -0
- package/deps/libutf/src/utf32/convert-to-utf16.c +56 -0
- package/deps/libutf/src/utf32/convert-to-utf8.c +71 -0
- package/deps/libutf/src/utf32/length-from-latin1.c +26 -0
- package/deps/libutf/src/utf32/length-from-utf16.c +35 -0
- package/deps/libutf/src/utf32/length-from-utf8.c +35 -0
- package/deps/libutf/src/utf32/string.c +149 -0
- package/deps/libutf/src/utf32/validate.c +39 -0
- package/deps/libutf/src/utf8/convert-to-latin1.c +70 -0
- package/deps/libutf/src/utf8/convert-to-utf16.c +95 -0
- package/deps/libutf/src/utf8/convert-to-utf32.c +110 -0
- package/deps/libutf/src/utf8/length-from-latin1.c +32 -0
- package/deps/libutf/src/utf8/length-from-utf16.c +48 -0
- package/deps/libutf/src/utf8/length-from-utf32.c +35 -0
- package/deps/libutf/src/utf8/string.c +149 -0
- package/deps/libutf/src/utf8/validate.c +107 -0
- package/deps/libutf/test/CMakeLists.txt +56 -0
- package/deps/libutf/test/fuzz/CMakeLists.txt +26 -0
- package/deps/libutf/test/fuzz/corpus/.gitignore +2 -0
- package/deps/libutf/test/fuzz/crashes/.gitignore +2 -0
- package/deps/libutf/test/fuzz/latin1/convert-to-utf16.c +32 -0
- package/deps/libutf/test/fuzz/latin1/convert-to-utf32.c +32 -0
- package/deps/libutf/test/fuzz/latin1/convert-to-utf8.c +33 -0
- package/deps/libutf/test/fuzz/utf16/convert-to-latin1.c +36 -0
- package/deps/libutf/test/fuzz/utf16/convert-to-utf32.c +38 -0
- package/deps/libutf/test/fuzz/utf16/convert-to-utf8.c +38 -0
- package/deps/libutf/test/fuzz/utf32/convert-to-latin1.c +36 -0
- package/deps/libutf/test/fuzz/utf32/convert-to-utf16.c +38 -0
- package/deps/libutf/test/fuzz/utf32/convert-to-utf8.c +38 -0
- package/deps/libutf/test/fuzz/utf8/convert-to-latin1.c +33 -0
- package/deps/libutf/test/fuzz/utf8/convert-to-utf16.c +35 -0
- package/deps/libutf/test/fuzz/utf8/convert-to-utf32.c +35 -0
- package/deps/libutf/test/utf16/utf8-convert.c +45 -0
- package/deps/libutf/test/utf16/utf8-length.c +41 -0
- package/deps/libutf/test/utf16/validate-invalid.c +50 -0
- package/deps/libutf/test/utf16/validate.c +32 -0
- package/deps/libutf/test/utf32/string-append.c +74 -0
- package/deps/libutf/test/utf32/string-compare.c +108 -0
- package/deps/libutf/test/utf32/string-erase.c +79 -0
- package/deps/libutf/test/utf32/string-index.c +102 -0
- package/deps/libutf/test/utf32/string-insert.c +92 -0
- package/deps/libutf/test/utf32/string-last-index.c +71 -0
- package/deps/libutf/test/utf32/string-prepend.c +51 -0
- package/deps/libutf/test/utf32/string-replace.c +88 -0
- package/deps/libutf/test/utf32/string-reserve.c +99 -0
- package/deps/libutf/test/utf32/string-substring.c +93 -0
- package/deps/libutf/test/utf8/latin1-convert.c +23 -0
- package/deps/libutf/test/utf8/string-append.c +23 -0
- package/deps/libutf/test/utf8/string-compare.c +67 -0
- package/deps/libutf/test/utf8/string-erase.c +75 -0
- package/deps/libutf/test/utf8/string-index.c +99 -0
- package/deps/libutf/test/utf8/string-last-index.c +68 -0
- package/deps/libutf/test/utf8/string-prepend.c +23 -0
- package/deps/libutf/test/utf8/string-replace.c +74 -0
- package/deps/libutf/test/utf8/string-reserve.c +51 -0
- package/deps/libutf/test/utf8/string-substring.c +68 -0
- package/deps/libutf/test/utf8/utf16-convert.c +32 -0
- package/deps/libutf/test/utf8/utf16-length.c +29 -0
- package/deps/libutf/test/utf8/validate-invalid.c +26 -0
- package/deps/libutf/test/utf8/validate.c +21 -0
- package/global.d.ts +21 -0
- package/global.js +6 -0
- package/index.d.ts +769 -0
- package/index.js +1339 -0
- package/lib/ascii.js +36 -0
- package/lib/base64.js +25 -0
- package/lib/base64url.js +25 -0
- package/lib/checked.js +23 -0
- package/lib/constants.d.ts +7 -0
- package/lib/constants.js +3 -0
- package/lib/hex.js +20 -0
- package/lib/latin1.js +14 -0
- package/lib/utf16le.js +20 -0
- package/lib/utf8.js +18 -0
- package/package.json +64 -0
package/lib/ascii.js
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
return string.length
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
9
|
+
const offset = buffer.byteOffset + start
|
|
10
|
+
const len = end - start
|
|
11
|
+
|
|
12
|
+
// ASCII is Latin-1 with the high bit unset, so as long as no high bits are set
|
|
13
|
+
// the native Latin-1 decoder produces the same string. Decoding through it
|
|
14
|
+
// either way keeps the range checked in one place.
|
|
15
|
+
const latin1 = binding.toStringLatin1(buffer.buffer, offset, len)
|
|
16
|
+
|
|
17
|
+
if (exports.validate(buffer, offset, len)) return latin1
|
|
18
|
+
|
|
19
|
+
let result = ''
|
|
20
|
+
|
|
21
|
+
for (let i = 0, n = latin1.length; i < n; i++) {
|
|
22
|
+
result += String.fromCharCode(latin1.charCodeAt(i) & 0x7f)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return result
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Encoding ASCII is equivalent to encoding Latin-1, both truncating each code
|
|
29
|
+
// unit to its low byte.
|
|
30
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
31
|
+
return checked(binding.writeLatin1(buffer.buffer, buffer.byteOffset + start, end - start, string))
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.validate = function validate(buffer, offset = buffer.byteOffset, len = buffer.byteLength) {
|
|
35
|
+
return checked(binding.validateAscii(buffer.buffer, offset, len)) === 1
|
|
36
|
+
}
|
package/lib/base64.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
let len = string.length
|
|
6
|
+
|
|
7
|
+
if (string.charCodeAt(len - 1) === 0x3d) len--
|
|
8
|
+
if (len > 1 && string.charCodeAt(len - 1) === 0x3d) len--
|
|
9
|
+
|
|
10
|
+
return (len * 3) >>> 2
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
14
|
+
return binding.toStringBase64(buffer.buffer, buffer.byteOffset + start, end - start)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
18
|
+
const written = checked(
|
|
19
|
+
binding.writeBase64(buffer.buffer, buffer.byteOffset + start, end - start, string)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if (written < 0) throw new Error('Invalid input')
|
|
23
|
+
|
|
24
|
+
return written
|
|
25
|
+
}
|
package/lib/base64url.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
let len = string.length
|
|
6
|
+
|
|
7
|
+
if (string.charCodeAt(len - 1) === 0x3d) len--
|
|
8
|
+
if (len > 1 && string.charCodeAt(len - 1) === 0x3d) len--
|
|
9
|
+
|
|
10
|
+
return (len * 3) >>> 2
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
14
|
+
return binding.toStringBase64URL(buffer.buffer, buffer.byteOffset + start, end - start)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
18
|
+
const written = checked(
|
|
19
|
+
binding.writeBase64(buffer.buffer, buffer.byteOffset + start, end - start, string)
|
|
20
|
+
)
|
|
21
|
+
|
|
22
|
+
if (written < 0) throw new Error('Invalid input')
|
|
23
|
+
|
|
24
|
+
return written
|
|
25
|
+
}
|
package/lib/checked.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
// A typed callback cannot raise, so the bindings report an argument they reject
|
|
2
|
+
// with a result no successful call can produce. There is one sentinel per error
|
|
3
|
+
// the untyped callback raises directly, so that the error does not change once
|
|
4
|
+
// V8 takes the fast path.
|
|
5
|
+
const OUT_OF_BOUNDS = -2147483648
|
|
6
|
+
const INVALID_BUFFER = -2147483647
|
|
7
|
+
const INVALID_STRING = -2147483646
|
|
8
|
+
|
|
9
|
+
module.exports = function checked(result) {
|
|
10
|
+
if (result === OUT_OF_BOUNDS) {
|
|
11
|
+
throw new RangeError('View is out of bounds of its backing store')
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (result === INVALID_BUFFER) {
|
|
15
|
+
throw new TypeError('Buffer must be an array buffer')
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
if (result === INVALID_STRING) {
|
|
19
|
+
throw new TypeError('String must be a string')
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return result
|
|
23
|
+
}
|
package/lib/constants.js
ADDED
package/lib/hex.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
return string.length >>> 1
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
9
|
+
return binding.toStringHex(buffer.buffer, buffer.byteOffset + start, end - start)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
13
|
+
const written = checked(
|
|
14
|
+
binding.writeHex(buffer.buffer, buffer.byteOffset + start, end - start, string)
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if (written < 0) throw new Error('Invalid input')
|
|
18
|
+
|
|
19
|
+
return written
|
|
20
|
+
}
|
package/lib/latin1.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
return string.length
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
9
|
+
return binding.toStringLatin1(buffer.buffer, buffer.byteOffset + start, end - start)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
13
|
+
return checked(binding.writeLatin1(buffer.buffer, buffer.byteOffset + start, end - start, string))
|
|
14
|
+
}
|
package/lib/utf16le.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
return string.length * 2
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
9
|
+
return binding.toStringUTF16LE(buffer.buffer, buffer.byteOffset + start, end - start)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
13
|
+
const written = checked(
|
|
14
|
+
binding.writeUTF16LE(buffer.buffer, buffer.byteOffset + start, end - start, string)
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
if (written < 0) throw new Error('Out of memory')
|
|
18
|
+
|
|
19
|
+
return written
|
|
20
|
+
}
|
package/lib/utf8.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const checked = require('./checked')
|
|
3
|
+
|
|
4
|
+
exports.byteLength = function byteLength(string) {
|
|
5
|
+
return checked(binding.byteLengthUTF8(string))
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
exports.toString = function toString(buffer, start = 0, end = buffer.byteLength) {
|
|
9
|
+
return binding.toStringUTF8(buffer.buffer, buffer.byteOffset + start, end - start)
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
exports.write = function write(buffer, string, start = 0, end = buffer.byteLength) {
|
|
13
|
+
return checked(binding.writeUTF8(buffer.buffer, buffer.byteOffset + start, end - start, string))
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.validate = function validate(buffer) {
|
|
17
|
+
return checked(binding.validateUTF8(buffer.buffer, buffer.byteOffset, buffer.byteLength)) === 1
|
|
18
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@ohos-ports/bare-buffer",
|
|
3
|
+
"version": "3.7.1-beta.0",
|
|
4
|
+
"description": "Native buffers for JavaScript",
|
|
5
|
+
"exports": {
|
|
6
|
+
"./package": "./package.json",
|
|
7
|
+
".": {
|
|
8
|
+
"types": "./index.d.ts",
|
|
9
|
+
"default": "./index.js"
|
|
10
|
+
},
|
|
11
|
+
"./global": {
|
|
12
|
+
"types": "./global.d.ts",
|
|
13
|
+
"default": "./global.js"
|
|
14
|
+
},
|
|
15
|
+
"./constants": {
|
|
16
|
+
"types": "./lib/constants.d.ts",
|
|
17
|
+
"default": "./lib/constants.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"index.js",
|
|
22
|
+
"index.d.ts",
|
|
23
|
+
"global.js",
|
|
24
|
+
"global.d.ts",
|
|
25
|
+
"binding.c",
|
|
26
|
+
"binding.js",
|
|
27
|
+
"lib",
|
|
28
|
+
"build/Release/*.node",
|
|
29
|
+
"binding.gyp",
|
|
30
|
+
"deps"
|
|
31
|
+
],
|
|
32
|
+
"addon": true,
|
|
33
|
+
"scripts": {
|
|
34
|
+
"format": "prettier --write . && lunte --fix",
|
|
35
|
+
"lint": "prettier --check . && lunte",
|
|
36
|
+
"test": "brittle-bare --coverage test.js"
|
|
37
|
+
},
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/ohos-ports/ohos-ports.git",
|
|
41
|
+
"directory": "ports/bare-buffer/3.7.1"
|
|
42
|
+
},
|
|
43
|
+
"author": "Holepunch",
|
|
44
|
+
"license": "Apache-2.0",
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/ohos-ports/ohos-ports/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/holepunchto/bare-buffer#readme",
|
|
49
|
+
"engines": {
|
|
50
|
+
"bare": ">=1.20.0"
|
|
51
|
+
},
|
|
52
|
+
"devDependencies": {
|
|
53
|
+
"bare-realm": "^2.0.1",
|
|
54
|
+
"brittle": "^3.1.1",
|
|
55
|
+
"cmake-bare": "^1.1.6",
|
|
56
|
+
"cmake-fetch": "^1.0.0",
|
|
57
|
+
"lunte": "^1.8.0",
|
|
58
|
+
"prettier": "^3.3.3",
|
|
59
|
+
"prettier-config-holepunch": "^2.0.0"
|
|
60
|
+
},
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"node-addon-api": "^8.9.2"
|
|
63
|
+
}
|
|
64
|
+
}
|