@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/index.d.ts
ADDED
|
@@ -0,0 +1,769 @@
|
|
|
1
|
+
import constants from './lib/constants'
|
|
2
|
+
|
|
3
|
+
/** The set of encodings supported by `Buffer` methods that convert between bytes and strings. */
|
|
4
|
+
type BufferEncoding =
|
|
5
|
+
| 'ascii'
|
|
6
|
+
| 'base64'
|
|
7
|
+
| 'binary'
|
|
8
|
+
| 'hex'
|
|
9
|
+
| 'latin1'
|
|
10
|
+
| 'ucs-2'
|
|
11
|
+
| 'ucs2'
|
|
12
|
+
| 'utf-16le'
|
|
13
|
+
| 'utf-8'
|
|
14
|
+
| 'utf16le'
|
|
15
|
+
| 'utf8'
|
|
16
|
+
|
|
17
|
+
interface Buffer extends Uint8Array<ArrayBuffer> {
|
|
18
|
+
/**
|
|
19
|
+
* Compare this buffer's contents against `target` lexicographically, optionally comparing only
|
|
20
|
+
* a sub-range of each, returning -1, 0, or 1 for sort ordering.
|
|
21
|
+
* @param target - The buffer to compare against.
|
|
22
|
+
* @param targetStart - Offset within `target` to start comparing from; defaults to `0`.
|
|
23
|
+
* @param targetEnd - Offset within `target` (exclusive) to stop comparing at; defaults to
|
|
24
|
+
* `target.byteLength`.
|
|
25
|
+
* @param sourceStart - Offset within this buffer to start comparing from; defaults to `0`.
|
|
26
|
+
* @param sourceEnd - Offset within this buffer (exclusive) to stop comparing at; defaults to
|
|
27
|
+
* `this.byteLength`.
|
|
28
|
+
* @throws {TypeError} thrown if `target` is not a view.
|
|
29
|
+
* @throws {RangeError} thrown if an offset or length is not an integer, or if either view's
|
|
30
|
+
* range lies outside its backing store.
|
|
31
|
+
*/
|
|
32
|
+
compare(
|
|
33
|
+
target: Buffer | ArrayBufferView,
|
|
34
|
+
targetStart?: number,
|
|
35
|
+
targetEnd?: number,
|
|
36
|
+
sourceStart?: number,
|
|
37
|
+
sourceEnd?: number
|
|
38
|
+
): number
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Copy bytes from this buffer into `target`, returning the number of bytes copied. A target of
|
|
42
|
+
* wider elements, such as a `Uint16Array`, receives the bytes it spans.
|
|
43
|
+
* @param target - The buffer or view to copy into.
|
|
44
|
+
* @param targetStart - Offset within `target` to start writing at; defaults to `0`.
|
|
45
|
+
* @param sourceStart - Offset within this buffer to start copying from; defaults to `0`.
|
|
46
|
+
* @param sourceEnd - Offset within this buffer (exclusive) to stop copying at; defaults to
|
|
47
|
+
* `this.byteLength`.
|
|
48
|
+
* @throws {TypeError} thrown if `target` is not a view.
|
|
49
|
+
* @throws {RangeError} thrown if an offset is not an integer, is negative, or if `sourceStart`
|
|
50
|
+
* is past the end of this buffer.
|
|
51
|
+
*/
|
|
52
|
+
copy(
|
|
53
|
+
target: Buffer | ArrayBufferView,
|
|
54
|
+
targetStart?: number,
|
|
55
|
+
sourceStart?: number,
|
|
56
|
+
sourceEnd?: number
|
|
57
|
+
): number
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Check whether this buffer and `target` have identical contents.
|
|
61
|
+
* @param target - The buffer or view to compare this buffer's contents against.
|
|
62
|
+
* @throws {TypeError} thrown if `target` is not a view.
|
|
63
|
+
* @throws {RangeError} thrown if either view's range lies outside its backing store.
|
|
64
|
+
*/
|
|
65
|
+
equals(target: Buffer | ArrayBufferView): boolean
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Fill this buffer with `value`, repeating as needed, and return it.
|
|
69
|
+
* @param value - The value to fill with — a string or view (repeated across the range), or a
|
|
70
|
+
* number/boolean byte. A view fills with the bytes it spans.
|
|
71
|
+
* @param encoding - Encoding used to interpret `value` when it's a string; defaults to `'utf8'`.
|
|
72
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
73
|
+
* @throws {TypeError} thrown if `value` is not a value that can fill.
|
|
74
|
+
* @throws {RangeError} thrown if an offset or length is not an integer.
|
|
75
|
+
*/
|
|
76
|
+
fill(value: string, encoding?: BufferEncoding): this
|
|
77
|
+
fill(value: string, offset?: number, encoding?: BufferEncoding): this
|
|
78
|
+
fill(value: string, offset?: number, end?: number, encoding?: BufferEncoding): this
|
|
79
|
+
fill(value: Buffer | ArrayBufferView | number | boolean, offset?: number, end?: number): this
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check whether this buffer contains `value`.
|
|
83
|
+
* @param value - The value to search for — a string, view, number byte, or boolean.
|
|
84
|
+
* @param encoding - Encoding used to interpret `value` when it's a string; defaults to `'utf8'`.
|
|
85
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
86
|
+
* @throws {TypeError} thrown if `value` is not a string, view, number, or boolean.
|
|
87
|
+
* @throws {RangeError} thrown if an offset or length is not an integer, or if either view's
|
|
88
|
+
* range lies outside its backing store.
|
|
89
|
+
*/
|
|
90
|
+
includes(value: string, encoding?: BufferEncoding): boolean
|
|
91
|
+
includes(value: string, offset?: number, encoding?: BufferEncoding): boolean
|
|
92
|
+
includes(value: Buffer | ArrayBufferView | number | boolean, offset?: number): boolean
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Return the first index at which `value` occurs in this buffer, or `-1` if not found.
|
|
96
|
+
* @param value - The value to search for — a string, view, number byte, or boolean.
|
|
97
|
+
* @param encoding - Encoding used to interpret `value` when it's a string; defaults to `'utf8'`.
|
|
98
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
99
|
+
* @throws {TypeError} thrown if `value` is not a string, view, number, or boolean.
|
|
100
|
+
* @throws {RangeError} thrown if an offset or length is not an integer, or if either view's
|
|
101
|
+
* range lies outside its backing store.
|
|
102
|
+
*/
|
|
103
|
+
indexOf(value: string, encoding?: BufferEncoding): number
|
|
104
|
+
indexOf(value: string, offset?: number, encoding?: BufferEncoding): number
|
|
105
|
+
indexOf(value: Buffer | ArrayBufferView | number | boolean, offset?: number): number
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Return the last index at which `value` occurs in this buffer, or `-1` if not found.
|
|
109
|
+
* @param value - The value to search for — a string, view, number byte, or boolean.
|
|
110
|
+
* @param encoding - Encoding used to interpret `value` when it's a string; defaults to `'utf8'`.
|
|
111
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
112
|
+
* @throws {TypeError} thrown if `value` is not a string, view, number, or boolean.
|
|
113
|
+
* @throws {RangeError} thrown if an offset or length is not an integer, or if either view's
|
|
114
|
+
* range lies outside its backing store.
|
|
115
|
+
*/
|
|
116
|
+
lastIndexOf(value: string, encoding?: BufferEncoding): number
|
|
117
|
+
lastIndexOf(value: string, offset?: number, encoding?: BufferEncoding): number
|
|
118
|
+
lastIndexOf(value: Buffer | ArrayBufferView | number | boolean, offset?: number): number
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Swap the byte order of each 16-bit group in this buffer in place, and return it.
|
|
122
|
+
* @throws {RangeError} thrown if the buffer's length is not a multiple of 2 bytes, or if its
|
|
123
|
+
* range lies outside its backing store.
|
|
124
|
+
*/
|
|
125
|
+
swap16(): this
|
|
126
|
+
/**
|
|
127
|
+
* Swap the byte order of each 32-bit group in this buffer in place, and return it.
|
|
128
|
+
* @throws {RangeError} thrown if the buffer's length is not a multiple of 4 bytes, or if its
|
|
129
|
+
* range lies outside its backing store.
|
|
130
|
+
*/
|
|
131
|
+
swap32(): this
|
|
132
|
+
/**
|
|
133
|
+
* Swap the byte order of each 64-bit group in this buffer in place, and return it.
|
|
134
|
+
* @throws {RangeError} thrown if the buffer's length is not a multiple of 8 bytes, or if its
|
|
135
|
+
* range lies outside its backing store.
|
|
136
|
+
*/
|
|
137
|
+
swap64(): this
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Decode this buffer (or a slice of it) to a string using `encoding`.
|
|
141
|
+
* @param encoding - Encoding used to decode the bytes; defaults to `'utf8'`.
|
|
142
|
+
* @param start - Byte offset to start decoding from; defaults to `0`.
|
|
143
|
+
* @param end - Byte offset (exclusive) to stop decoding at; defaults to `this.byteLength`.
|
|
144
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
145
|
+
* @throws {RangeError} thrown if an offset or length is not an integer, if this buffer's range
|
|
146
|
+
* lies outside its backing store, or if the decoded string would exceed
|
|
147
|
+
* `Buffer.constants.MAX_STRING_LENGTH`.
|
|
148
|
+
*/
|
|
149
|
+
toString(encoding?: BufferEncoding, start?: number, end?: number): string
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Return an array of this buffer's bytes, used when the buffer is passed to `JSON.stringify()`.
|
|
153
|
+
*/
|
|
154
|
+
toJSON(): number[]
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* Read a 64-bit big-endian double at `offset`.
|
|
158
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
159
|
+
*/
|
|
160
|
+
readDoubleBE(offset?: number): number
|
|
161
|
+
/**
|
|
162
|
+
* Read a 64-bit little-endian double at `offset`.
|
|
163
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
164
|
+
*/
|
|
165
|
+
readDoubleLE(offset?: number): number
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Read a 32-bit big-endian float at `offset`.
|
|
169
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
170
|
+
*/
|
|
171
|
+
readFloatBE(offset?: number): number
|
|
172
|
+
/**
|
|
173
|
+
* Read a 32-bit little-endian float at `offset`.
|
|
174
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
175
|
+
*/
|
|
176
|
+
readFloatLE(offset?: number): number
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Read a signed 8-bit integer at `offset`.
|
|
180
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
181
|
+
*/
|
|
182
|
+
readInt8(offset?: number): number
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Read a signed 16-bit big-endian integer at `offset`.
|
|
186
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
187
|
+
*/
|
|
188
|
+
readInt16BE(offset?: number): number
|
|
189
|
+
/**
|
|
190
|
+
* Read a signed 16-bit little-endian integer at `offset`.
|
|
191
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
192
|
+
*/
|
|
193
|
+
readInt16LE(offset?: number): number
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Read a signed 32-bit big-endian integer at `offset`.
|
|
197
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
198
|
+
*/
|
|
199
|
+
readInt32BE(offset?: number): number
|
|
200
|
+
/**
|
|
201
|
+
* Read a signed 32-bit little-endian integer at `offset`.
|
|
202
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
203
|
+
*/
|
|
204
|
+
readInt32LE(offset?: number): number
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Read a signed, big-endian, `byteLength`-byte integer at `offset`.
|
|
208
|
+
* @param offset - Byte offset to read from.
|
|
209
|
+
* @param byteLength - Number of bytes to read, from `1` to `6`.
|
|
210
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
211
|
+
*/
|
|
212
|
+
readIntBE(offset: number, byteLength: number): number
|
|
213
|
+
/**
|
|
214
|
+
* Read a signed, little-endian, `byteLength`-byte integer at `offset`.
|
|
215
|
+
* @param offset - Byte offset to read from.
|
|
216
|
+
* @param byteLength - Number of bytes to read, from `1` to `6`.
|
|
217
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
218
|
+
*/
|
|
219
|
+
readIntLE(offset: number, byteLength: number): number
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* Read a signed 64-bit big-endian integer at `offset`.
|
|
223
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
224
|
+
*/
|
|
225
|
+
readBigInt64BE(offset?: number): bigint
|
|
226
|
+
/**
|
|
227
|
+
* Read a signed 64-bit little-endian integer at `offset`.
|
|
228
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
229
|
+
*/
|
|
230
|
+
readBigInt64LE(offset?: number): bigint
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* Read an unsigned 8-bit integer at `offset`.
|
|
234
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
235
|
+
*/
|
|
236
|
+
readUInt8(offset?: number): number
|
|
237
|
+
/**
|
|
238
|
+
* Read an unsigned 8-bit integer at `offset`.
|
|
239
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
240
|
+
*/
|
|
241
|
+
readUint8(offset?: number): number
|
|
242
|
+
|
|
243
|
+
/**
|
|
244
|
+
* Read an unsigned 16-bit big-endian integer at `offset`.
|
|
245
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
246
|
+
*/
|
|
247
|
+
readUInt16BE(offset?: number): number
|
|
248
|
+
/**
|
|
249
|
+
* Read an unsigned 16-bit big-endian integer at `offset`.
|
|
250
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
251
|
+
*/
|
|
252
|
+
readUint16BE(offset?: number): number
|
|
253
|
+
/**
|
|
254
|
+
* Read an unsigned 16-bit little-endian integer at `offset`.
|
|
255
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
256
|
+
*/
|
|
257
|
+
readUInt16LE(offset?: number): number
|
|
258
|
+
/**
|
|
259
|
+
* Read an unsigned 16-bit little-endian integer at `offset`.
|
|
260
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
261
|
+
*/
|
|
262
|
+
readUint16LE(offset?: number): number
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Read an unsigned 32-bit big-endian integer at `offset`.
|
|
266
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
267
|
+
*/
|
|
268
|
+
readUInt32BE(offset?: number): number
|
|
269
|
+
/**
|
|
270
|
+
* Read an unsigned 32-bit big-endian integer at `offset`.
|
|
271
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
272
|
+
*/
|
|
273
|
+
readUint32BE(offset?: number): number
|
|
274
|
+
/**
|
|
275
|
+
* Read an unsigned 32-bit little-endian integer at `offset`.
|
|
276
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
277
|
+
*/
|
|
278
|
+
readUInt32LE(offset?: number): number
|
|
279
|
+
/**
|
|
280
|
+
* Read an unsigned 32-bit little-endian integer at `offset`.
|
|
281
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
282
|
+
*/
|
|
283
|
+
readUint32LE(offset?: number): number
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Read an unsigned, big-endian, `byteLength`-byte integer at `offset`.
|
|
287
|
+
* @param offset - Byte offset to read from.
|
|
288
|
+
* @param byteLength - Number of bytes to read, from `1` to `6`.
|
|
289
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
290
|
+
*/
|
|
291
|
+
readUIntBE(offset: number, byteLength: number): number
|
|
292
|
+
/**
|
|
293
|
+
* Read an unsigned, big-endian, `byteLength`-byte integer at `offset`.
|
|
294
|
+
* @param offset - Byte offset to read from.
|
|
295
|
+
* @param byteLength - Number of bytes to read, from `1` to `6`.
|
|
296
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
297
|
+
*/
|
|
298
|
+
readUintBE(offset: number, byteLength: number): number
|
|
299
|
+
/**
|
|
300
|
+
* Read an unsigned, little-endian, `byteLength`-byte integer at `offset`.
|
|
301
|
+
* @param offset - Byte offset to read from.
|
|
302
|
+
* @param byteLength - Number of bytes to read, from `1` to `6`.
|
|
303
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
304
|
+
*/
|
|
305
|
+
readUIntLE(offset: number, byteLength: number): number
|
|
306
|
+
/**
|
|
307
|
+
* Read an unsigned, little-endian, `byteLength`-byte integer at `offset`.
|
|
308
|
+
* @param offset - Byte offset to read from.
|
|
309
|
+
* @param byteLength - Number of bytes to read, from `1` to `6`.
|
|
310
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
311
|
+
*/
|
|
312
|
+
readUintLE(offset: number, byteLength: number): number
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* Read an unsigned 64-bit big-endian integer at `offset`.
|
|
316
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
317
|
+
*/
|
|
318
|
+
readBigUInt64BE(offset?: number): bigint
|
|
319
|
+
/**
|
|
320
|
+
* Read an unsigned 64-bit big-endian integer at `offset`.
|
|
321
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
322
|
+
*/
|
|
323
|
+
readBigUint64BE(offset?: number): bigint
|
|
324
|
+
/**
|
|
325
|
+
* Read an unsigned 64-bit little-endian integer at `offset`.
|
|
326
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
327
|
+
*/
|
|
328
|
+
readBigUInt64LE(offset?: number): bigint
|
|
329
|
+
/**
|
|
330
|
+
* Read an unsigned 64-bit little-endian integer at `offset`.
|
|
331
|
+
* @param offset - Byte offset to read from; defaults to `0`.
|
|
332
|
+
*/
|
|
333
|
+
readBigUint64LE(offset?: number): bigint
|
|
334
|
+
|
|
335
|
+
/**
|
|
336
|
+
* Write `string` into this buffer using `encoding`, returning the number of bytes written.
|
|
337
|
+
* @param string - The string to write.
|
|
338
|
+
* @param encoding - Encoding used to encode `string`; defaults to `'utf8'`.
|
|
339
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`, or if `string`
|
|
340
|
+
* is not valid in it, as a hex or base64 string can fail to be.
|
|
341
|
+
* @throws {TypeError} thrown if `string` is not a string.
|
|
342
|
+
* @throws {RangeError} thrown if an offset or length is not an integer, or if this buffer's
|
|
343
|
+
* range lies outside its backing store.
|
|
344
|
+
*/
|
|
345
|
+
write(string: string, encoding?: BufferEncoding): number
|
|
346
|
+
write(string: string, offset?: number, encoding?: BufferEncoding): number
|
|
347
|
+
write(string: string, offset?: number, length?: number, encoding?: BufferEncoding): number
|
|
348
|
+
|
|
349
|
+
/**
|
|
350
|
+
* Write a 64-bit big-endian double at `offset`.
|
|
351
|
+
* @param value - The double-precision number to write.
|
|
352
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
353
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
354
|
+
*/
|
|
355
|
+
writeDoubleBE(value: number, offset?: number): number
|
|
356
|
+
/**
|
|
357
|
+
* Write a 64-bit little-endian double at `offset`.
|
|
358
|
+
* @param value - The double-precision number to write.
|
|
359
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
360
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
361
|
+
*/
|
|
362
|
+
writeDoubleLE(value: number, offset?: number): number
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* Write a 32-bit big-endian float at `offset`.
|
|
366
|
+
* @param value - The single-precision number to write.
|
|
367
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
368
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
369
|
+
*/
|
|
370
|
+
writeFloatBE(value: number, offset?: number): number
|
|
371
|
+
/**
|
|
372
|
+
* Write a 32-bit little-endian float at `offset`.
|
|
373
|
+
* @param value - The single-precision number to write.
|
|
374
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
375
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
376
|
+
*/
|
|
377
|
+
writeFloatLE(value: number, offset?: number): number
|
|
378
|
+
|
|
379
|
+
/**
|
|
380
|
+
* Write a signed 8-bit integer at `offset`.
|
|
381
|
+
* @param value - The signed integer to write.
|
|
382
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
383
|
+
* @returns `offset + 1`, the offset immediately following the written value.
|
|
384
|
+
*/
|
|
385
|
+
writeInt8(value: number, offset?: number): number
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Write a signed 16-bit big-endian integer at `offset`.
|
|
389
|
+
* @param value - The signed integer to write.
|
|
390
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
391
|
+
* @returns `offset + 2`, the offset immediately following the written value.
|
|
392
|
+
*/
|
|
393
|
+
writeInt16BE(value: number, offset?: number): number
|
|
394
|
+
/**
|
|
395
|
+
* Write a signed 16-bit little-endian integer at `offset`.
|
|
396
|
+
* @param value - The signed integer to write.
|
|
397
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
398
|
+
* @returns `offset + 2`, the offset immediately following the written value.
|
|
399
|
+
*/
|
|
400
|
+
writeInt16LE(value: number, offset?: number): number
|
|
401
|
+
|
|
402
|
+
/**
|
|
403
|
+
* Write a signed 32-bit big-endian integer at `offset`.
|
|
404
|
+
* @param value - The signed integer to write.
|
|
405
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
406
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
407
|
+
*/
|
|
408
|
+
writeInt32BE(value: number, offset?: number): number
|
|
409
|
+
/**
|
|
410
|
+
* Write a signed 32-bit little-endian integer at `offset`.
|
|
411
|
+
* @param value - The signed integer to write.
|
|
412
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
413
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
414
|
+
*/
|
|
415
|
+
writeInt32LE(value: number, offset?: number): number
|
|
416
|
+
|
|
417
|
+
/**
|
|
418
|
+
* Write a signed, big-endian, `byteLength`-byte integer at `offset`.
|
|
419
|
+
* @param value - The signed integer to write.
|
|
420
|
+
* @param offset - Byte offset to write to.
|
|
421
|
+
* @param byteLength - Number of bytes to write, from `1` to `6`.
|
|
422
|
+
* @returns `offset + byteLength`, the offset immediately following the written value.
|
|
423
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
424
|
+
*/
|
|
425
|
+
writeIntBE(value: number, offset: number, byteLength: number): number
|
|
426
|
+
/**
|
|
427
|
+
* Write a signed, little-endian, `byteLength`-byte integer at `offset`.
|
|
428
|
+
* @param value - The signed integer to write.
|
|
429
|
+
* @param offset - Byte offset to write to.
|
|
430
|
+
* @param byteLength - Number of bytes to write, from `1` to `6`.
|
|
431
|
+
* @returns `offset + byteLength`, the offset immediately following the written value.
|
|
432
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
433
|
+
*/
|
|
434
|
+
writeIntLE(value: number, offset: number, byteLength: number): number
|
|
435
|
+
|
|
436
|
+
/**
|
|
437
|
+
* Write a signed 64-bit big-endian integer at `offset`.
|
|
438
|
+
* @param value - The signed `bigint` to write.
|
|
439
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
440
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
441
|
+
*/
|
|
442
|
+
writeBigInt64BE(value: bigint, offset?: number): number
|
|
443
|
+
/**
|
|
444
|
+
* Write a signed 64-bit little-endian integer at `offset`.
|
|
445
|
+
* @param value - The signed `bigint` to write.
|
|
446
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
447
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
448
|
+
*/
|
|
449
|
+
writeBigInt64LE(value: bigint, offset?: number): number
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Write an unsigned 8-bit integer at `offset`.
|
|
453
|
+
* @param value - The unsigned integer to write.
|
|
454
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
455
|
+
* @returns `offset + 1`, the offset immediately following the written value.
|
|
456
|
+
*/
|
|
457
|
+
writeUInt8(value: number, offset?: number): number
|
|
458
|
+
/**
|
|
459
|
+
* Write an unsigned 8-bit integer at `offset`.
|
|
460
|
+
* @param value - The unsigned integer to write.
|
|
461
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
462
|
+
* @returns `offset + 1`, the offset immediately following the written value.
|
|
463
|
+
*/
|
|
464
|
+
writeUint8(value: number, offset?: number): number
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Write an unsigned 16-bit big-endian integer at `offset`.
|
|
468
|
+
* @param value - The unsigned integer to write.
|
|
469
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
470
|
+
* @returns `offset + 2`, the offset immediately following the written value.
|
|
471
|
+
*/
|
|
472
|
+
writeUInt16BE(value: number, offset?: number): number
|
|
473
|
+
/**
|
|
474
|
+
* Write an unsigned 16-bit big-endian integer at `offset`.
|
|
475
|
+
* @param value - The unsigned integer to write.
|
|
476
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
477
|
+
* @returns `offset + 2`, the offset immediately following the written value.
|
|
478
|
+
*/
|
|
479
|
+
writeUint16BE(value: number, offset?: number): number
|
|
480
|
+
/**
|
|
481
|
+
* Write an unsigned 16-bit little-endian integer at `offset`.
|
|
482
|
+
* @param value - The unsigned integer to write.
|
|
483
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
484
|
+
* @returns `offset + 2`, the offset immediately following the written value.
|
|
485
|
+
*/
|
|
486
|
+
writeUInt16LE(value: number, offset?: number): number
|
|
487
|
+
/**
|
|
488
|
+
* Write an unsigned 16-bit little-endian integer at `offset`.
|
|
489
|
+
* @param value - The unsigned integer to write.
|
|
490
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
491
|
+
* @returns `offset + 2`, the offset immediately following the written value.
|
|
492
|
+
*/
|
|
493
|
+
writeUint16LE(value: number, offset?: number): number
|
|
494
|
+
|
|
495
|
+
/**
|
|
496
|
+
* Write an unsigned 32-bit big-endian integer at `offset`.
|
|
497
|
+
* @param value - The unsigned integer to write.
|
|
498
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
499
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
500
|
+
*/
|
|
501
|
+
writeUInt32BE(value: number, offset?: number): number
|
|
502
|
+
/**
|
|
503
|
+
* Write an unsigned 32-bit big-endian integer at `offset`.
|
|
504
|
+
* @param value - The unsigned integer to write.
|
|
505
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
506
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
507
|
+
*/
|
|
508
|
+
writeUint32BE(value: number, offset?: number): number
|
|
509
|
+
/**
|
|
510
|
+
* Write an unsigned 32-bit little-endian integer at `offset`.
|
|
511
|
+
* @param value - The unsigned integer to write.
|
|
512
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
513
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
514
|
+
*/
|
|
515
|
+
writeUInt32LE(value: number, offset?: number): number
|
|
516
|
+
/**
|
|
517
|
+
* Write an unsigned 32-bit little-endian integer at `offset`.
|
|
518
|
+
* @param value - The unsigned integer to write.
|
|
519
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
520
|
+
* @returns `offset + 4`, the offset immediately following the written value.
|
|
521
|
+
*/
|
|
522
|
+
writeUint32LE(value: number, offset?: number): number
|
|
523
|
+
|
|
524
|
+
/**
|
|
525
|
+
* Write an unsigned, big-endian, `byteLength`-byte integer at `offset`.
|
|
526
|
+
* @param value - The unsigned integer to write.
|
|
527
|
+
* @param offset - Byte offset to write to.
|
|
528
|
+
* @param byteLength - Number of bytes to write, from `1` to `6`.
|
|
529
|
+
* @returns `offset + byteLength`, the offset immediately following the written value.
|
|
530
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
531
|
+
*/
|
|
532
|
+
writeUIntBE(value: number, offset: number, byteLength: number): number
|
|
533
|
+
/**
|
|
534
|
+
* Write an unsigned, big-endian, `byteLength`-byte integer at `offset`.
|
|
535
|
+
* @param value - The unsigned integer to write.
|
|
536
|
+
* @param offset - Byte offset to write to.
|
|
537
|
+
* @param byteLength - Number of bytes to write, from `1` to `6`.
|
|
538
|
+
* @returns `offset + byteLength`, the offset immediately following the written value.
|
|
539
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
540
|
+
*/
|
|
541
|
+
writeUintBE(value: number, offset: number, byteLength: number): number
|
|
542
|
+
/**
|
|
543
|
+
* Write an unsigned, little-endian, `byteLength`-byte integer at `offset`.
|
|
544
|
+
* @param value - The unsigned integer to write.
|
|
545
|
+
* @param offset - Byte offset to write to.
|
|
546
|
+
* @param byteLength - Number of bytes to write, from `1` to `6`.
|
|
547
|
+
* @returns `offset + byteLength`, the offset immediately following the written value.
|
|
548
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
549
|
+
*/
|
|
550
|
+
writeUIntLE(value: number, offset: number, byteLength: number): number
|
|
551
|
+
/**
|
|
552
|
+
* Write an unsigned, little-endian, `byteLength`-byte integer at `offset`.
|
|
553
|
+
* @param value - The unsigned integer to write.
|
|
554
|
+
* @param offset - Byte offset to write to.
|
|
555
|
+
* @param byteLength - Number of bytes to write, from `1` to `6`.
|
|
556
|
+
* @returns `offset + byteLength`, the offset immediately following the written value.
|
|
557
|
+
* @throws {RangeError} thrown if `byteLength` is not between `1` and `6`.
|
|
558
|
+
*/
|
|
559
|
+
writeUintLE(value: number, offset: number, byteLength: number): number
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Write an unsigned 64-bit big-endian integer at `offset`.
|
|
563
|
+
* @param value - The unsigned `bigint` to write.
|
|
564
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
565
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
566
|
+
*/
|
|
567
|
+
writeBigUint64BE(value: bigint, offset?: number): number
|
|
568
|
+
/**
|
|
569
|
+
* Write an unsigned 64-bit big-endian integer at `offset`.
|
|
570
|
+
* @param value - The unsigned `bigint` to write.
|
|
571
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
572
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
573
|
+
*/
|
|
574
|
+
writeBigUInt64BE(value: bigint, offset?: number): number
|
|
575
|
+
/**
|
|
576
|
+
* Write an unsigned 64-bit little-endian integer at `offset`.
|
|
577
|
+
* @param value - The unsigned `bigint` to write.
|
|
578
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
579
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
580
|
+
*/
|
|
581
|
+
writeBigUint64LE(value: bigint, offset?: number): number
|
|
582
|
+
/**
|
|
583
|
+
* Write an unsigned 64-bit little-endian integer at `offset`.
|
|
584
|
+
* @param value - The unsigned `bigint` to write.
|
|
585
|
+
* @param offset - Byte offset to write to; defaults to `0`.
|
|
586
|
+
* @returns `offset + 8`, the offset immediately following the written value.
|
|
587
|
+
*/
|
|
588
|
+
writeBigUInt64LE(value: bigint, offset?: number): number
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
declare class Buffer extends Uint8Array<ArrayBuffer> {
|
|
592
|
+
/**
|
|
593
|
+
* Create a `Buffer` viewing `arrayBuffer`, optionally starting at `offset` for `length` bytes.
|
|
594
|
+
* @param arrayBuffer - The `ArrayBuffer` to view.
|
|
595
|
+
* @param offset - Byte offset into `arrayBuffer` to start the view at; defaults to `0`.
|
|
596
|
+
* @param length - Number of bytes to view from `offset`; defaults to the rest of `arrayBuffer`.
|
|
597
|
+
* @throws {RangeError} thrown if the resulting length would exceed `Buffer.constants.MAX_LENGTH`.
|
|
598
|
+
*/
|
|
599
|
+
constructor(arrayBuffer: ArrayBuffer, offset?: number, length?: number)
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/** A fixed-length view of binary data, backed by an `ArrayBuffer` and extending `Uint8Array`. */
|
|
603
|
+
declare namespace Buffer {
|
|
604
|
+
/**
|
|
605
|
+
* The size, in bytes, of the internal buffer pool used to satisfy small allocations. Setting it
|
|
606
|
+
* to `0` turns pooling off.
|
|
607
|
+
* @throws {TypeError} thrown if assigned a value that is not a number.
|
|
608
|
+
* @throws {RangeError} thrown if assigned a value that is not an integer between `0` and
|
|
609
|
+
* `Buffer.constants.MAX_LENGTH`.
|
|
610
|
+
*/
|
|
611
|
+
export let poolSize: number
|
|
612
|
+
|
|
613
|
+
/**
|
|
614
|
+
* Check whether `value` is a `Buffer`.
|
|
615
|
+
* @param value - The value to check.
|
|
616
|
+
*/
|
|
617
|
+
export function isBuffer(value: unknown): value is Buffer
|
|
618
|
+
|
|
619
|
+
/**
|
|
620
|
+
* Check whether `encoding` is a supported `BufferEncoding`.
|
|
621
|
+
* @param encoding - The encoding name to check.
|
|
622
|
+
*/
|
|
623
|
+
export function isEncoding(encoding: string): encoding is BufferEncoding
|
|
624
|
+
|
|
625
|
+
/**
|
|
626
|
+
* Check whether `buffer` contains only valid ASCII-encoded data.
|
|
627
|
+
* @param buffer - The buffer or view to check.
|
|
628
|
+
* @throws {TypeError} thrown if `buffer` is not a view.
|
|
629
|
+
* @throws {RangeError} thrown if `buffer`'s range lies outside its backing store.
|
|
630
|
+
*/
|
|
631
|
+
export function isASCII(buffer: Buffer | ArrayBufferView): boolean
|
|
632
|
+
/**
|
|
633
|
+
* Check whether `buffer` contains only valid ASCII-encoded data.
|
|
634
|
+
* @param buffer - The buffer or view to check.
|
|
635
|
+
* @throws {TypeError} thrown if `buffer` is not a view.
|
|
636
|
+
* @throws {RangeError} thrown if `buffer`'s range lies outside its backing store.
|
|
637
|
+
*/
|
|
638
|
+
export function isAscii(buffer: Buffer | ArrayBufferView): boolean
|
|
639
|
+
|
|
640
|
+
/**
|
|
641
|
+
* Check whether `buffer` contains only valid UTF-8-encoded data.
|
|
642
|
+
* @param buffer - The buffer or view to check.
|
|
643
|
+
* @throws {TypeError} thrown if `buffer` is not a view.
|
|
644
|
+
* @throws {RangeError} thrown if `buffer`'s range lies outside its backing store.
|
|
645
|
+
*/
|
|
646
|
+
export function isUTF8(buffer: Buffer | ArrayBufferView): boolean
|
|
647
|
+
/**
|
|
648
|
+
* Check whether `buffer` contains only valid UTF-8-encoded data.
|
|
649
|
+
* @param buffer - The buffer or view to check.
|
|
650
|
+
* @throws {TypeError} thrown if `buffer` is not a view.
|
|
651
|
+
* @throws {RangeError} thrown if `buffer`'s range lies outside its backing store.
|
|
652
|
+
*/
|
|
653
|
+
export function isUtf8(buffer: Buffer | ArrayBufferView): boolean
|
|
654
|
+
|
|
655
|
+
/**
|
|
656
|
+
* Allocate a new, zero-filled `Buffer` of `size` bytes, optionally filled with `fill`.
|
|
657
|
+
* @param size - Number of bytes to allocate.
|
|
658
|
+
* @param fill - Value to fill the buffer with — a string, view, number byte, or boolean.
|
|
659
|
+
* @param encoding - Encoding used to interpret `fill` when it's a string; defaults to `'utf8'`.
|
|
660
|
+
* @throws {RangeError} thrown if `size` is not an integer between `0` and
|
|
661
|
+
* `Buffer.constants.MAX_LENGTH`.
|
|
662
|
+
* @throws {TypeError} thrown if `size` is not a number, or `fill` is not a value that can fill.
|
|
663
|
+
*/
|
|
664
|
+
export function alloc(size: number, fill: string, encoding?: BufferEncoding): Buffer
|
|
665
|
+
export function alloc(size: number, fill?: Buffer | ArrayBufferView | number | boolean): Buffer
|
|
666
|
+
|
|
667
|
+
/**
|
|
668
|
+
* Allocate a new `Buffer` of `size` bytes without zeroing its contents first.
|
|
669
|
+
* @param size - Number of bytes to allocate.
|
|
670
|
+
* @throws {RangeError} thrown if `size` is not an integer between `0` and
|
|
671
|
+
* `Buffer.constants.MAX_LENGTH`.
|
|
672
|
+
* @throws {TypeError} thrown if `size` is not a number.
|
|
673
|
+
*/
|
|
674
|
+
export function allocUnsafe(size: number): Buffer
|
|
675
|
+
|
|
676
|
+
/**
|
|
677
|
+
* Allocate a new `Buffer` of `size` bytes without zeroing its contents first, bypassing the
|
|
678
|
+
* internal buffer pool.
|
|
679
|
+
* @param size - Number of bytes to allocate.
|
|
680
|
+
* @throws {RangeError} thrown if `size` is not an integer between `0` and
|
|
681
|
+
* `Buffer.constants.MAX_LENGTH`.
|
|
682
|
+
* @throws {TypeError} thrown if `size` is not a number.
|
|
683
|
+
*/
|
|
684
|
+
export function allocUnsafeSlow(size: number): Buffer
|
|
685
|
+
|
|
686
|
+
/**
|
|
687
|
+
* Return the number of bytes `string` would occupy once encoded as `encoding`.
|
|
688
|
+
* @param string - The value whose encoded length to measure — a string, or an
|
|
689
|
+
* `ArrayBufferView`/`ArrayBufferLike` (whose own `byteLength` is returned unchanged).
|
|
690
|
+
* @param encoding - Encoding used to measure `string` when it's a string; defaults to `'utf8'`.
|
|
691
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
692
|
+
*/
|
|
693
|
+
export function byteLength(
|
|
694
|
+
string: ArrayBufferView | ArrayBufferLike | string,
|
|
695
|
+
encoding?: BufferEncoding
|
|
696
|
+
): number
|
|
697
|
+
|
|
698
|
+
/**
|
|
699
|
+
* Compare two buffers' contents lexicographically, returning -1, 0, or 1 for sort ordering.
|
|
700
|
+
* @param a - The first buffer to compare.
|
|
701
|
+
* @param b - The second buffer to compare.
|
|
702
|
+
* @throws {TypeError} thrown if `a` or `b` is not a view.
|
|
703
|
+
* @throws {RangeError} thrown if either view's range lies outside its backing store.
|
|
704
|
+
*/
|
|
705
|
+
export function compare(a: Buffer | ArrayBufferView, b: Buffer | ArrayBufferView): number
|
|
706
|
+
|
|
707
|
+
/**
|
|
708
|
+
* Concatenate `buffers` into a single new `Buffer`, optionally truncated or zero-padded to
|
|
709
|
+
* `length`.
|
|
710
|
+
* @param buffers - The buffers to concatenate, in order.
|
|
711
|
+
* @param length - Total byte length of the result; defaults to the sum of `buffers`' lengths.
|
|
712
|
+
* @throws {RangeError} thrown if an offset or length is not an integer.
|
|
713
|
+
*/
|
|
714
|
+
export function concat(buffers: Buffer[], length?: number): Buffer
|
|
715
|
+
|
|
716
|
+
/**
|
|
717
|
+
* Return `buffer` unchanged if it is already a `Buffer`, otherwise wrap its underlying
|
|
718
|
+
* `ArrayBuffer` in a new `Buffer`.
|
|
719
|
+
* @param buffer - The buffer or view to coerce into a `Buffer`.
|
|
720
|
+
*/
|
|
721
|
+
export function coerce(buffer: Buffer | ArrayBufferView): Buffer
|
|
722
|
+
|
|
723
|
+
/**
|
|
724
|
+
* Copy the bytes of `view`, starting at `offset` for `length` elements, into a new `Buffer`.
|
|
725
|
+
* @param view - The typed array (or other `ArrayBufferLike` view) to copy bytes from.
|
|
726
|
+
* @param offset - Index of the first element to copy; defaults to `0`.
|
|
727
|
+
* @param length - Number of elements to copy; defaults to the rest of `view`.
|
|
728
|
+
* @throws {RangeError} thrown if `offset + length` exceeds `view.length`.
|
|
729
|
+
* @throws {RangeError} thrown if an offset or length is not an integer.
|
|
730
|
+
*/
|
|
731
|
+
export function copyBytesFrom(view: ArrayBufferLike, offset?: number, length?: number): Buffer
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Create a new `Buffer` from an array, array-like, string, or `ArrayBuffer`.
|
|
735
|
+
* @param data - The array, array-like, string, buffer, or `ArrayBuffer` to create a new `Buffer`
|
|
736
|
+
* from.
|
|
737
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`, or if `string`
|
|
738
|
+
* is not valid in it, as a hex or base64 string can fail to be.
|
|
739
|
+
* @throws {RangeError} thrown if an offset or length is not an integer.
|
|
740
|
+
*/
|
|
741
|
+
export function from(data: Iterable<number>): Buffer
|
|
742
|
+
export function from(data: ArrayLike<number>): Buffer
|
|
743
|
+
export function from(string: string, encoding?: BufferEncoding): Buffer
|
|
744
|
+
export function from(arrayBuffer: ArrayBufferLike, offset?: number, length?: number): Buffer
|
|
745
|
+
|
|
746
|
+
/**
|
|
747
|
+
* Decode a base64-encoded string into a Latin-1 binary string.
|
|
748
|
+
* @param data - The base64-encoded string to decode.
|
|
749
|
+
*/
|
|
750
|
+
export function atob(data: unknown): string
|
|
751
|
+
/**
|
|
752
|
+
* Encode a Latin-1 binary string into a base64 string.
|
|
753
|
+
* @param data - The value to encode; non-strings are coerced with `String()`.
|
|
754
|
+
*/
|
|
755
|
+
export function btoa(data: unknown): string
|
|
756
|
+
|
|
757
|
+
/**
|
|
758
|
+
* Re-encode `buffer` from one encoding to another, returning a new `Buffer`.
|
|
759
|
+
* @param buffer - The buffer to re-encode.
|
|
760
|
+
* @param from - The encoding `buffer` is currently in.
|
|
761
|
+
* @param to - The encoding to convert to.
|
|
762
|
+
* @throws {Error} thrown if the encoding is not a recognized `BufferEncoding`.
|
|
763
|
+
*/
|
|
764
|
+
export function transcode(buffer: Buffer, from: BufferEncoding, to: BufferEncoding): Buffer
|
|
765
|
+
|
|
766
|
+
export { Buffer, type BufferEncoding, constants }
|
|
767
|
+
}
|
|
768
|
+
|
|
769
|
+
export = Buffer
|