@tothalex/cloud 0.0.40
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/package.json +19 -0
- package/src/abort.d.ts +69 -0
- package/src/assert.d.ts +39 -0
- package/src/buffer.d.ts +556 -0
- package/src/child_process.d.ts +447 -0
- package/src/crypto.d.ts +854 -0
- package/src/database.d.ts +0 -0
- package/src/dns.d.ts +99 -0
- package/src/events.d.ts +245 -0
- package/src/exceptions.d.ts +26 -0
- package/src/http.d.ts +325 -0
- package/src/index.d.ts +22 -0
- package/src/net.d.ts +488 -0
- package/src/os.d.ts +293 -0
- package/src/process.d.ts +379 -0
- package/src/stream.d.ts +366 -0
- package/src/string_decoder.d.ts +63 -0
- package/src/timers.d.ts +72 -0
- package/src/tty.d.ts +10 -0
- package/src/url.d.ts +774 -0
- package/src/util.d.ts +240 -0
- package/src/zlib.d.ts +149 -0
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tothalex/cloud",
|
|
3
|
+
"version": "0.0.40",
|
|
4
|
+
"main": "",
|
|
5
|
+
"types": "./src/index.d.ts",
|
|
6
|
+
"files": [
|
|
7
|
+
"src/*.d.ts"
|
|
8
|
+
],
|
|
9
|
+
"scripts": {
|
|
10
|
+
"build": "tsc",
|
|
11
|
+
"clean": "rm -rf dist"
|
|
12
|
+
},
|
|
13
|
+
"devDependencies": {
|
|
14
|
+
"typescript": "^5.2.2"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@types/node": "^24.0.4"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/src/abort.d.ts
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
declare global {
|
|
4
|
+
class AbortController {
|
|
5
|
+
/**
|
|
6
|
+
* Creates a new `AbortController` object instance.
|
|
7
|
+
*/
|
|
8
|
+
constructor();
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Returns the AbortSignal object associated with this object.
|
|
12
|
+
*/
|
|
13
|
+
readonly signal: AbortSignal;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Invoking this method will set this object's AbortSignal's aborted flag and signal to any observers that the associated activity is to be aborted.
|
|
17
|
+
*/
|
|
18
|
+
abort(reason?: any): void;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/** A signal object that allows you to communicate with a DOM request (such as a Fetch) and abort it if required via an AbortController object. */
|
|
22
|
+
class AbortSignal extends EventTarget {
|
|
23
|
+
/**
|
|
24
|
+
* Creates a new `AbortSignal` object instance.
|
|
25
|
+
*/
|
|
26
|
+
constructor();
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Returns true if this AbortSignal's AbortController has signaled to abort, and false otherwise.
|
|
30
|
+
*/
|
|
31
|
+
readonly aborted: boolean;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* A JavaScript value providing the abort reason, once the signal has aborted.
|
|
35
|
+
*/
|
|
36
|
+
readonly reason: any;
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Registers an event listener callback to execute when an `abort` event is observed.
|
|
40
|
+
*/
|
|
41
|
+
onabort: null | ((this: AbortSignal, event: Event) => any);
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Throws the signal's abort reason if the signal has been aborted; otherwise it does nothing.
|
|
45
|
+
*/
|
|
46
|
+
throwIfAborted(): void;
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Returns an `AbortSignal` instance that is already set as aborted.
|
|
50
|
+
*
|
|
51
|
+
* @param reason The reason for the abort.
|
|
52
|
+
*/
|
|
53
|
+
static abort(reason?: any): AbortSignal;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Returns an `AbortSignal` instance that will automatically abort after a specified time.
|
|
57
|
+
*
|
|
58
|
+
* @param milliseconds The number of milliseconds to wait before aborting.
|
|
59
|
+
*/
|
|
60
|
+
static timeout(milliseconds: number): AbortSignal;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Returns an `AbortSignal` that aborts when any of the given abort signals abort.
|
|
64
|
+
*
|
|
65
|
+
* @param signals An array of `AbortSignal` objects to observe.
|
|
66
|
+
*/
|
|
67
|
+
static any(signals: AbortSignal[]): AbortSignal;
|
|
68
|
+
}
|
|
69
|
+
}
|
package/src/assert.d.ts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The `assert` module provides a set of assertion functions for verifying invariants.
|
|
3
|
+
*/
|
|
4
|
+
declare module 'assert' {
|
|
5
|
+
/**
|
|
6
|
+
* An alias of {@link ok}.
|
|
7
|
+
* @param value The input that is checked for being truthy.
|
|
8
|
+
*/
|
|
9
|
+
function assert(value: unknown, message?: string | Error): asserts value
|
|
10
|
+
/**
|
|
11
|
+
* Tests if `value` is truthy.
|
|
12
|
+
*
|
|
13
|
+
* If `value` is not truthy, an `AssertionError` is thrown with a `message` property set equal to the value of the `message` parameter. If the `message` parameter is `undefined`, a default
|
|
14
|
+
* error message is assigned. If the `message` parameter is an instance of an `Error` then it will be thrown instead of the `AssertionError`.
|
|
15
|
+
* If no arguments are passed in at all `message` will be set to the string:`` 'No value argument passed to `assert.ok()`' ``.
|
|
16
|
+
*
|
|
17
|
+
* ```js
|
|
18
|
+
* import * as assert from 'assert';
|
|
19
|
+
*
|
|
20
|
+
* assert.ok(true);
|
|
21
|
+
* // OK
|
|
22
|
+
* assert.ok(1);
|
|
23
|
+
* // OK
|
|
24
|
+
*
|
|
25
|
+
* assert.ok();
|
|
26
|
+
* // TypeError: Error calling function with 0 argument(s) while 1 where expected
|
|
27
|
+
*
|
|
28
|
+
* assert.ok(false, 'it\'s false');
|
|
29
|
+
* // AssertionError: it's false
|
|
30
|
+
*
|
|
31
|
+
* assert.ok(false);
|
|
32
|
+
* // AssertionError: The expression was evaluated to a falsy value
|
|
33
|
+
*
|
|
34
|
+
* assert.ok(0);
|
|
35
|
+
* // AssertionError: The expression was evaluated to a falsy value
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
function ok(value: unknown, message?: string | Error): asserts value
|
|
39
|
+
}
|
package/src/buffer.d.ts
ADDED
|
@@ -0,0 +1,556 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
|
|
3
|
+
* LLRT APIs support `Buffer`s.
|
|
4
|
+
*
|
|
5
|
+
* The `Buffer` class is a subclass of JavaScript's [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) class and
|
|
6
|
+
* extends it with methods that cover additional use cases. LLRT APIs accept
|
|
7
|
+
* plain [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) s wherever `Buffer`s are supported as well.
|
|
8
|
+
*
|
|
9
|
+
* While the `Buffer` class is available within the global scope, it is still
|
|
10
|
+
* recommended to explicitly reference it via an import or require statement.
|
|
11
|
+
*
|
|
12
|
+
* ```js
|
|
13
|
+
* import { Buffer } from 'buffer';
|
|
14
|
+
*
|
|
15
|
+
* // Creates a zero-filled Buffer of length 10.
|
|
16
|
+
* const buf1 = Buffer.alloc(10);
|
|
17
|
+
*
|
|
18
|
+
* // Creates a Buffer of length 10,
|
|
19
|
+
* // filled with bytes which all have the value `1`.
|
|
20
|
+
* const buf2 = Buffer.alloc(10, 1);
|
|
21
|
+
*
|
|
22
|
+
* // Creates a Buffer containing the bytes [1, 2, 3].
|
|
23
|
+
* const buf4 = Buffer.from([1, 2, 3]);
|
|
24
|
+
*
|
|
25
|
+
* // Creates a Buffer containing the bytes [1, 1, 1, 1] – the entries
|
|
26
|
+
* // are all truncated using `(value & 255)` to fit into the range 0–255.
|
|
27
|
+
* const buf5 = Buffer.from([257, 257.5, -255, '1']);
|
|
28
|
+
*
|
|
29
|
+
* // Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
|
|
30
|
+
* // [0x74, 0xc3, 0xa9, 0x73, 0x74] (in hexadecimal notation)
|
|
31
|
+
* // [116, 195, 169, 115, 116] (in decimal notation)
|
|
32
|
+
* const buf6 = Buffer.from('tést');
|
|
33
|
+
*
|
|
34
|
+
* // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
|
|
35
|
+
* const buf7 = Buffer.from('tést', 'latin1');
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
declare module 'buffer' {
|
|
39
|
+
export const constants: {
|
|
40
|
+
MAX_LENGTH: number
|
|
41
|
+
MAX_STRING_LENGTH: number
|
|
42
|
+
}
|
|
43
|
+
export type BufferEncoding =
|
|
44
|
+
| 'hex'
|
|
45
|
+
| 'base64'
|
|
46
|
+
| 'utf-8'
|
|
47
|
+
| 'utf8'
|
|
48
|
+
| 'unicode-1-1-utf8'
|
|
49
|
+
| 'utf-16le'
|
|
50
|
+
| 'utf16le'
|
|
51
|
+
| 'utf-16'
|
|
52
|
+
| 'utf16'
|
|
53
|
+
| 'utf-16be'
|
|
54
|
+
| 'utf16be'
|
|
55
|
+
| 'windows-1252'
|
|
56
|
+
| 'ansi_x3.4-1968'
|
|
57
|
+
| 'ascii'
|
|
58
|
+
| 'cp1252'
|
|
59
|
+
| 'cp819'
|
|
60
|
+
| 'csisolatin1'
|
|
61
|
+
| 'ibm819'
|
|
62
|
+
| 'iso-8859-1'
|
|
63
|
+
| 'iso-ir-100'
|
|
64
|
+
| 'iso8859-1'
|
|
65
|
+
| 'iso88591'
|
|
66
|
+
| 'iso_8859-1'
|
|
67
|
+
| 'iso_8859-1:1987'
|
|
68
|
+
| 'l1'
|
|
69
|
+
| 'latin1'
|
|
70
|
+
| 'us-ascii'
|
|
71
|
+
| 'x-cp1252'
|
|
72
|
+
type WithImplicitCoercion<T> =
|
|
73
|
+
| T
|
|
74
|
+
| {
|
|
75
|
+
valueOf(): T
|
|
76
|
+
}
|
|
77
|
+
interface BufferConstructor {
|
|
78
|
+
/**
|
|
79
|
+
* Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the `Buffer` will be zero-filled.
|
|
80
|
+
*
|
|
81
|
+
* ```js
|
|
82
|
+
* import { Buffer } from 'buffer';
|
|
83
|
+
*
|
|
84
|
+
* const buf = Buffer.alloc(5);
|
|
85
|
+
*
|
|
86
|
+
* console.log(buf);
|
|
87
|
+
* // Prints: <Buffer 00 00 00 00 00>
|
|
88
|
+
* ```
|
|
89
|
+
*
|
|
90
|
+
* If `fill` is specified, the allocated `Buffer` will be initialized by calling `Buffer.alloc(size, fill)`.
|
|
91
|
+
*
|
|
92
|
+
* ```js
|
|
93
|
+
* import { Buffer } from 'buffer';
|
|
94
|
+
*
|
|
95
|
+
* const buf = Buffer.alloc(5, 'a');
|
|
96
|
+
*
|
|
97
|
+
* console.log(buf);
|
|
98
|
+
* // Prints: <Buffer 61 61 61 61 61>
|
|
99
|
+
* ```
|
|
100
|
+
*
|
|
101
|
+
* If both `fill` and `encoding` are specified, the allocated `Buffer` will be
|
|
102
|
+
* initialized by calling `Buffer.aloc(size, fill, encoding)`.
|
|
103
|
+
*
|
|
104
|
+
* ```js
|
|
105
|
+
* import { Buffer } from 'buffer';
|
|
106
|
+
*
|
|
107
|
+
* const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
|
|
108
|
+
*
|
|
109
|
+
* console.log(buf);
|
|
110
|
+
* // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
|
|
111
|
+
* ```
|
|
112
|
+
*
|
|
113
|
+
* @param size The desired length of the new `Buffer`.
|
|
114
|
+
* @param [fill=0] A value to pre-fill the new `Buffer` with.
|
|
115
|
+
* @param [encoding='utf8'] If `fill` is a string, this is its encoding.
|
|
116
|
+
*/
|
|
117
|
+
alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer
|
|
118
|
+
/**
|
|
119
|
+
* Returns the byte length of a string when encoded using `encoding`.
|
|
120
|
+
* This is not the same as [`String.prototype.length`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length), which does not account
|
|
121
|
+
* for the encoding that is used to convert the string into bytes.
|
|
122
|
+
*
|
|
123
|
+
* ```js
|
|
124
|
+
* import { Buffer } from 'buffer';
|
|
125
|
+
*
|
|
126
|
+
* const str = '\u00bd + \u00bc = \u00be';
|
|
127
|
+
*
|
|
128
|
+
* console.log(`${str}: ${str.length} characters, ` +
|
|
129
|
+
* `${Buffer.byteLength(str, 'utf8')} bytes`);
|
|
130
|
+
* // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
|
|
131
|
+
* ```
|
|
132
|
+
*
|
|
133
|
+
* When `string` is a
|
|
134
|
+
* `Buffer`/[`DataView`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView)/[`TypedArray`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/-
|
|
135
|
+
* Reference/Global_Objects/TypedArray)/[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)/[`SharedArrayBuffer`](https://develop-
|
|
136
|
+
* er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by `.byteLength`is returned.
|
|
137
|
+
* @param string A value to calculate the length of.
|
|
138
|
+
* @param [encoding='utf8'] If `string` is a string, this is its encoding.
|
|
139
|
+
* @return The number of bytes contained within `string`.
|
|
140
|
+
*/
|
|
141
|
+
byteLength(
|
|
142
|
+
string: string | Buffer | QuickJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
|
|
143
|
+
encoding?: BufferEncoding
|
|
144
|
+
): number
|
|
145
|
+
/**
|
|
146
|
+
* Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together.
|
|
147
|
+
*
|
|
148
|
+
* If the list has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned.
|
|
149
|
+
*
|
|
150
|
+
* If `totalLength` is not provided, it is calculated from the `Buffer` instances
|
|
151
|
+
* in `list` by adding their lengths.
|
|
152
|
+
*
|
|
153
|
+
* If `totalLength` is provided, it is coerced to an unsigned integer. If the
|
|
154
|
+
* combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
|
|
155
|
+
* truncated to `totalLength`.
|
|
156
|
+
*
|
|
157
|
+
* ```js
|
|
158
|
+
* import { Buffer } from 'buffer';
|
|
159
|
+
*
|
|
160
|
+
* // Create a single `Buffer` from a list of three `Buffer` instances.
|
|
161
|
+
*
|
|
162
|
+
* const buf1 = Buffer.alloc(10);
|
|
163
|
+
* const buf2 = Buffer.alloc(14);
|
|
164
|
+
* const buf3 = Buffer.alloc(18);
|
|
165
|
+
* const totalLength = buf1.length + buf2.length + buf3.length;
|
|
166
|
+
*
|
|
167
|
+
* console.log(totalLength);
|
|
168
|
+
* // Prints: 42
|
|
169
|
+
*
|
|
170
|
+
* const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
|
|
171
|
+
*
|
|
172
|
+
* console.log(bufA);
|
|
173
|
+
* // Prints: <Buffer 00 00 00 00 ...>
|
|
174
|
+
* console.log(bufA.length);
|
|
175
|
+
* // Prints: 42
|
|
176
|
+
* ```
|
|
177
|
+
*
|
|
178
|
+
* @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.
|
|
179
|
+
* @param totalLength Total length of the `Buffer` instances in `list` when concatenated.
|
|
180
|
+
*/
|
|
181
|
+
concat(list: readonly Uint8Array[], totalLength?: number): Buffer
|
|
182
|
+
/**
|
|
183
|
+
* Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
|
|
184
|
+
*/
|
|
185
|
+
from(
|
|
186
|
+
arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>,
|
|
187
|
+
byteOffset?: number,
|
|
188
|
+
length?: number
|
|
189
|
+
): Buffer
|
|
190
|
+
/**
|
|
191
|
+
* Creates a new Buffer using the passed {data}
|
|
192
|
+
* @param data data to create a new Buffer
|
|
193
|
+
*/
|
|
194
|
+
from(data: Uint8Array | readonly number[]): Buffer
|
|
195
|
+
from(data: WithImplicitCoercion<Uint8Array | readonly number[] | string>): Buffer
|
|
196
|
+
/**
|
|
197
|
+
* Creates a new Buffer containing the given JavaScript string {str}.
|
|
198
|
+
* If provided, the {encoding} parameter identifies the character encoding.
|
|
199
|
+
* If not provided, {encoding} defaults to 'utf8'.
|
|
200
|
+
*/
|
|
201
|
+
from(
|
|
202
|
+
str:
|
|
203
|
+
| WithImplicitCoercion<string>
|
|
204
|
+
| {
|
|
205
|
+
[Symbol.toPrimitive](hint: 'string'): string
|
|
206
|
+
},
|
|
207
|
+
encoding?: BufferEncoding
|
|
208
|
+
): Buffer
|
|
209
|
+
}
|
|
210
|
+
interface Buffer extends Uint8Array {
|
|
211
|
+
/**
|
|
212
|
+
* Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
|
|
213
|
+
*
|
|
214
|
+
* [`TypedArray.prototype.set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set) performs the same operation, and is available
|
|
215
|
+
* for all TypedArrays, including `Buffer`s, although it takes
|
|
216
|
+
* different function arguments.
|
|
217
|
+
*
|
|
218
|
+
* ```js
|
|
219
|
+
* import { Buffer } from 'buffer';
|
|
220
|
+
*
|
|
221
|
+
* // Create two `Buffer` instances.
|
|
222
|
+
* const buf1 = Buffer.allocUnsafe(26);
|
|
223
|
+
* const buf2 = Buffer.allocUnsafe(26).fill('!');
|
|
224
|
+
*
|
|
225
|
+
* for (let i = 0; i < 26; i++) {
|
|
226
|
+
* // 97 is the decimal ASCII value for 'a'.
|
|
227
|
+
* buf1[i] = i + 97;
|
|
228
|
+
* }
|
|
229
|
+
*
|
|
230
|
+
* // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
|
|
231
|
+
* buf1.copy(buf2, 8, 16, 20);
|
|
232
|
+
* // This is equivalent to:
|
|
233
|
+
* // buf2.set(buf1.subarray(16, 20), 8);
|
|
234
|
+
*
|
|
235
|
+
* console.log(buf2.toString('ascii', 0, 25));
|
|
236
|
+
* // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
|
|
237
|
+
* ```
|
|
238
|
+
*
|
|
239
|
+
* ```js
|
|
240
|
+
* import { Buffer } from 'buffer';
|
|
241
|
+
*
|
|
242
|
+
* // Create a `Buffer` and copy data from one region to an overlapping region
|
|
243
|
+
* // within the same `Buffer`.
|
|
244
|
+
*
|
|
245
|
+
* const buf = Buffer.allocUnsafe(26);
|
|
246
|
+
*
|
|
247
|
+
* for (let i = 0; i < 26; i++) {
|
|
248
|
+
* // 97 is the decimal ASCII value for 'a'.
|
|
249
|
+
* buf[i] = i + 97;
|
|
250
|
+
* }
|
|
251
|
+
*
|
|
252
|
+
* buf.copy(buf, 0, 4, 10);
|
|
253
|
+
*
|
|
254
|
+
* console.log(buf.toString());
|
|
255
|
+
* // Prints: efghijghijklmnopqrstuvwxyz
|
|
256
|
+
* ```
|
|
257
|
+
* @param target A `Buffer` or {@link Uint8Array} to copy into.
|
|
258
|
+
* @param [targetStart=0] The offset within `target` at which to begin writing.
|
|
259
|
+
* @param [sourceStart=0] The offset within `buf` from which to begin copying.
|
|
260
|
+
* @param [sourceEnd=buf.length] The offset within `buf` at which to stop copying (not inclusive).
|
|
261
|
+
* @return The number of bytes copied.
|
|
262
|
+
*/
|
|
263
|
+
copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number
|
|
264
|
+
/**
|
|
265
|
+
* Returns a new `Buffer` that references the same memory as the original, but
|
|
266
|
+
* offset and cropped by the `start` and `end` indices.
|
|
267
|
+
*
|
|
268
|
+
* Specifying `end` greater than `buf.length` will return the same result as
|
|
269
|
+
* that of `end` equal to `buf.length`.
|
|
270
|
+
*
|
|
271
|
+
* This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
|
|
272
|
+
*
|
|
273
|
+
* Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
|
|
274
|
+
*
|
|
275
|
+
* ```js
|
|
276
|
+
* import { Buffer } from 'buffer';
|
|
277
|
+
*
|
|
278
|
+
* // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
|
|
279
|
+
* // from the original `Buffer`.
|
|
280
|
+
*
|
|
281
|
+
* const buf1 = Buffer.alloc(26);
|
|
282
|
+
*
|
|
283
|
+
* for (let i = 0; i < 26; i++) {
|
|
284
|
+
* // 97 is the decimal ASCII value for 'a'.
|
|
285
|
+
* buf1[i] = i + 97;
|
|
286
|
+
* }
|
|
287
|
+
*
|
|
288
|
+
* const buf2 = buf1.subarray(0, 3);
|
|
289
|
+
*
|
|
290
|
+
* console.log(buf2.toString('ascii', 0, buf2.length));
|
|
291
|
+
* // Prints: abc
|
|
292
|
+
*
|
|
293
|
+
* buf1[0] = 33;
|
|
294
|
+
*
|
|
295
|
+
* console.log(buf2.toString('ascii', 0, buf2.length));
|
|
296
|
+
* // Prints: !bc
|
|
297
|
+
* ```
|
|
298
|
+
*
|
|
299
|
+
* Specifying negative indexes causes the slice to be generated relative to the
|
|
300
|
+
* end of `buf` rather than the beginning.
|
|
301
|
+
*
|
|
302
|
+
* ```js
|
|
303
|
+
* import { Buffer } from 'buffer';
|
|
304
|
+
*
|
|
305
|
+
* const buf = Buffer.from('buffer');
|
|
306
|
+
*
|
|
307
|
+
* console.log(buf.subarray(-6, -1).toString());
|
|
308
|
+
* // Prints: buffe
|
|
309
|
+
* // (Equivalent to buf.subarray(0, 5).)
|
|
310
|
+
*
|
|
311
|
+
* console.log(buf.subarray(-6, -2).toString());
|
|
312
|
+
* // Prints: buff
|
|
313
|
+
* // (Equivalent to buf.subarray(0, 4).)
|
|
314
|
+
*
|
|
315
|
+
* console.log(buf.subarray(-5, -2).toString());
|
|
316
|
+
* // Prints: uff
|
|
317
|
+
* // (Equivalent to buf.subarray(1, 4).)
|
|
318
|
+
* ```
|
|
319
|
+
* @param [start=0] Where the new `Buffer` will start.
|
|
320
|
+
* @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
|
|
321
|
+
*/
|
|
322
|
+
subarray(start?: number, end?: number): Buffer
|
|
323
|
+
/**
|
|
324
|
+
* Decodes `buf` to a string according to the specified character encoding in`encoding`.
|
|
325
|
+
*
|
|
326
|
+
* If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
|
|
327
|
+
* then each invalid byte is replaced with the replacement character `U+FFFD`.
|
|
328
|
+
*
|
|
329
|
+
* ```js
|
|
330
|
+
* import { Buffer } from 'buffer';
|
|
331
|
+
*
|
|
332
|
+
* const buf1 = Buffer.alloc(26);
|
|
333
|
+
*
|
|
334
|
+
* for (let i = 0; i < 26; i++) {
|
|
335
|
+
* // 97 is the decimal ASCII value for 'a'.
|
|
336
|
+
* buf1[i] = i + 97;
|
|
337
|
+
* }
|
|
338
|
+
*
|
|
339
|
+
* console.log(buf1.toString('utf8'));
|
|
340
|
+
* // Prints: abcdefghijklmnopqrstuvwxyz
|
|
341
|
+
*
|
|
342
|
+
* const buf2 = Buffer.from('tést');
|
|
343
|
+
*
|
|
344
|
+
* console.log(buf2.toString('hex'));
|
|
345
|
+
* // Prints: 74c3a97374
|
|
346
|
+
* ```
|
|
347
|
+
* @param [encoding='utf8'] The character encoding to use.
|
|
348
|
+
*/
|
|
349
|
+
toString(encoding?: BufferEncoding): string
|
|
350
|
+
/**
|
|
351
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything
|
|
352
|
+
* other than a JavaScript number.
|
|
353
|
+
*
|
|
354
|
+
* ```js
|
|
355
|
+
* import { Buffer } from 'buffer';
|
|
356
|
+
*
|
|
357
|
+
* const buf = Buffer.allocUnsafe(8);
|
|
358
|
+
*
|
|
359
|
+
* buf.writeDoubleLE(123.456, 0);
|
|
360
|
+
*
|
|
361
|
+
* console.log(buf);
|
|
362
|
+
* // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
|
|
363
|
+
* ```
|
|
364
|
+
* @param value Number to be written to `buf`.
|
|
365
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
|
366
|
+
* @return `offset` plus the number of bytes written.
|
|
367
|
+
*/
|
|
368
|
+
writeDoubleLE(value: number, offset?: number): number
|
|
369
|
+
/**
|
|
370
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a JavaScript number. Behavior is undefined when `value` is anything
|
|
371
|
+
* other than a JavaScript number.
|
|
372
|
+
*
|
|
373
|
+
* ```js
|
|
374
|
+
* import { Buffer } from 'buffer';
|
|
375
|
+
*
|
|
376
|
+
* const buf = Buffer.allocUnsafe(8);
|
|
377
|
+
*
|
|
378
|
+
* buf.writeDoubleBE(123.456, 0);
|
|
379
|
+
*
|
|
380
|
+
* console.log(buf);
|
|
381
|
+
* // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
|
|
382
|
+
* ```
|
|
383
|
+
* @param value Number to be written to `buf`.
|
|
384
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
|
|
385
|
+
* @return `offset` plus the number of bytes written.
|
|
386
|
+
*/
|
|
387
|
+
writeDoubleBE(value: number, offset?: number): number
|
|
388
|
+
/**
|
|
389
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
|
|
390
|
+
* undefined when `value` is anything other than a JavaScript number.
|
|
391
|
+
*
|
|
392
|
+
* ```js
|
|
393
|
+
* import { Buffer } from 'buffer';
|
|
394
|
+
*
|
|
395
|
+
* const buf = Buffer.allocUnsafe(4);
|
|
396
|
+
*
|
|
397
|
+
* buf.writeFloatLE(0xcafebabe, 0);
|
|
398
|
+
*
|
|
399
|
+
* console.log(buf);
|
|
400
|
+
* // Prints: <Buffer bb fe 4a 4f>
|
|
401
|
+
* ```
|
|
402
|
+
* @param value Number to be written to `buf`.
|
|
403
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
|
404
|
+
* @return `offset` plus the number of bytes written.
|
|
405
|
+
*/
|
|
406
|
+
writeFloatLE(value: number, offset?: number): number
|
|
407
|
+
/**
|
|
408
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
|
|
409
|
+
* undefined when `value` is anything other than a JavaScript number.
|
|
410
|
+
*
|
|
411
|
+
* ```js
|
|
412
|
+
* import { Buffer } from 'buffer';
|
|
413
|
+
*
|
|
414
|
+
* const buf = Buffer.allocUnsafe(4);
|
|
415
|
+
*
|
|
416
|
+
* buf.writeFloatBE(0xcafebabe, 0);
|
|
417
|
+
*
|
|
418
|
+
* console.log(buf);
|
|
419
|
+
* // Prints: <Buffer 4f 4a fe bb>
|
|
420
|
+
* ```
|
|
421
|
+
* @param value Number to be written to `buf`.
|
|
422
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
|
423
|
+
* @return `offset` plus the number of bytes written.
|
|
424
|
+
*/
|
|
425
|
+
writeFloatBE(value: number, offset?: number): number
|
|
426
|
+
/**
|
|
427
|
+
* Writes `value` to `buf` at the specified `offset`. `value` must be a valid
|
|
428
|
+
* signed 8-bit integer. Behavior is undefined when `value` is anything other than
|
|
429
|
+
* a signed 8-bit integer.
|
|
430
|
+
*
|
|
431
|
+
* `value` is interpreted and written as a two's complement signed integer.
|
|
432
|
+
*
|
|
433
|
+
* ```js
|
|
434
|
+
* import { Buffer } from 'buffer';
|
|
435
|
+
*
|
|
436
|
+
* const buf = Buffer.allocUnsafe(2);
|
|
437
|
+
*
|
|
438
|
+
* buf.writeInt8(2, 0);
|
|
439
|
+
* buf.writeInt8(-2, 1);
|
|
440
|
+
*
|
|
441
|
+
* console.log(buf);
|
|
442
|
+
* // Prints: <Buffer 02 fe>
|
|
443
|
+
* ```
|
|
444
|
+
* @param value Number to be written to `buf`.
|
|
445
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
|
|
446
|
+
* @return `offset` plus the number of bytes written.
|
|
447
|
+
*/
|
|
448
|
+
writeInt8(value: number, offset?: number): number
|
|
449
|
+
/**
|
|
450
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 16-bit integer. Behavior is undefined when `value` is
|
|
451
|
+
* anything other than a signed 16-bit integer.
|
|
452
|
+
*
|
|
453
|
+
* The `value` is interpreted and written as a two's complement signed integer.
|
|
454
|
+
*
|
|
455
|
+
* ```js
|
|
456
|
+
* import { Buffer } from 'buffer';
|
|
457
|
+
*
|
|
458
|
+
* const buf = Buffer.allocUnsafe(2);
|
|
459
|
+
*
|
|
460
|
+
* buf.writeInt16LE(0x0304, 0);
|
|
461
|
+
*
|
|
462
|
+
* console.log(buf);
|
|
463
|
+
* // Prints: <Buffer 04 03>
|
|
464
|
+
* ```
|
|
465
|
+
* @param value Number to be written to `buf`.
|
|
466
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
|
467
|
+
* @return `offset` plus the number of bytes written.
|
|
468
|
+
*/
|
|
469
|
+
writeInt16LE(value: number, offset?: number): number
|
|
470
|
+
/**
|
|
471
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 16-bit integer. Behavior is undefined when `value` is
|
|
472
|
+
* anything other than a signed 16-bit integer.
|
|
473
|
+
*
|
|
474
|
+
* The `value` is interpreted and written as a two's complement signed integer.
|
|
475
|
+
*
|
|
476
|
+
* ```js
|
|
477
|
+
* import { Buffer } from 'buffer';
|
|
478
|
+
*
|
|
479
|
+
* const buf = Buffer.allocUnsafe(2);
|
|
480
|
+
*
|
|
481
|
+
* buf.writeInt16BE(0x0102, 0);
|
|
482
|
+
*
|
|
483
|
+
* console.log(buf);
|
|
484
|
+
* // Prints: <Buffer 01 02>
|
|
485
|
+
* ```
|
|
486
|
+
* @param value Number to be written to `buf`.
|
|
487
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
|
|
488
|
+
* @return `offset` plus the number of bytes written.
|
|
489
|
+
*/
|
|
490
|
+
writeInt16BE(value: number, offset?: number): number
|
|
491
|
+
/**
|
|
492
|
+
* Writes `value` to `buf` at the specified `offset` as little-endian. The `value` must be a valid signed 32-bit integer. Behavior is undefined when `value` is
|
|
493
|
+
* anything other than a signed 32-bit integer.
|
|
494
|
+
*
|
|
495
|
+
* The `value` is interpreted and written as a two's complement signed integer.
|
|
496
|
+
*
|
|
497
|
+
* ```js
|
|
498
|
+
* import { Buffer } from 'buffer';
|
|
499
|
+
*
|
|
500
|
+
* const buf = Buffer.allocUnsafe(4);
|
|
501
|
+
*
|
|
502
|
+
* buf.writeInt32LE(0x05060708, 0);
|
|
503
|
+
*
|
|
504
|
+
* console.log(buf);
|
|
505
|
+
* // Prints: <Buffer 08 07 06 05>
|
|
506
|
+
* ```
|
|
507
|
+
* @param value Number to be written to `buf`.
|
|
508
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
|
509
|
+
* @return `offset` plus the number of bytes written.
|
|
510
|
+
*/
|
|
511
|
+
writeInt32LE(value: number, offset?: number): number
|
|
512
|
+
/**
|
|
513
|
+
* Writes `value` to `buf` at the specified `offset` as big-endian. The `value` must be a valid signed 32-bit integer. Behavior is undefined when `value` is
|
|
514
|
+
* anything other than a signed 32-bit integer.
|
|
515
|
+
*
|
|
516
|
+
* The `value` is interpreted and written as a two's complement signed integer.
|
|
517
|
+
*
|
|
518
|
+
* ```js
|
|
519
|
+
* import { Buffer } from 'buffer';
|
|
520
|
+
*
|
|
521
|
+
* const buf = Buffer.allocUnsafe(4);
|
|
522
|
+
*
|
|
523
|
+
* buf.writeInt32BE(0x01020304, 0);
|
|
524
|
+
*
|
|
525
|
+
* console.log(buf);
|
|
526
|
+
* // Prints: <Buffer 01 02 03 04>
|
|
527
|
+
* ```
|
|
528
|
+
* @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
|
|
529
|
+
* @return `offset` plus the number of bytes written.
|
|
530
|
+
*/
|
|
531
|
+
writeInt32BE(value: number, offset?: number): number
|
|
532
|
+
}
|
|
533
|
+
var Buffer: BufferConstructor
|
|
534
|
+
/**
|
|
535
|
+
* Decodes a string of Base64-encoded data into bytes, and encodes those bytes
|
|
536
|
+
* into a string using UTF-8.
|
|
537
|
+
*
|
|
538
|
+
* The `data` may be any JavaScript-value that can be coerced into a string.
|
|
539
|
+
*
|
|
540
|
+
* @legacy Use `Buffer.from(data, 'base64')` instead.
|
|
541
|
+
* @param data The Base64-encoded input string.
|
|
542
|
+
*/
|
|
543
|
+
function atob(data: string): string
|
|
544
|
+
/**
|
|
545
|
+
* Decodes a string into bytes using UTF-8, and encodes those bytes
|
|
546
|
+
* into a string using Base64.
|
|
547
|
+
*
|
|
548
|
+
* The `data` may be any JavaScript-value that can be coerced into a string.
|
|
549
|
+
*
|
|
550
|
+
* @legacy Use `buf.toString('base64')` instead.
|
|
551
|
+
* @param data An ASCII (Latin1) string.
|
|
552
|
+
*/
|
|
553
|
+
function btoa(data: string): string
|
|
554
|
+
|
|
555
|
+
export { Buffer, atob, btoa }
|
|
556
|
+
}
|