@shopify/ui-extensions-server-kit 0.0.0-snapshot-20240816145941 → 0.0.0-snapshot-20250604200552

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.
Files changed (143) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/dist/ExtensionServerClient/ExtensionServerClient.cjs.js +1 -1
  3. package/dist/ExtensionServerClient/ExtensionServerClient.es.js +1 -1
  4. package/dist/context/ExtensionServerProvider.cjs.js +1 -1
  5. package/dist/context/ExtensionServerProvider.es.js +13 -12
  6. package/dist/index.cjs.js +1 -1
  7. package/dist/index.es.js +37 -36
  8. package/dist/state/actions/actions.cjs.js +1 -1
  9. package/dist/state/actions/actions.d.ts +2 -1
  10. package/dist/state/actions/actions.es.js +7 -0
  11. package/dist/state/actions/types.d.ts +5 -1
  12. package/dist/testing/extensions.cjs.js +1 -1
  13. package/dist/testing/extensions.es.js +2 -2
  14. package/dist/types.d.ts +8 -0
  15. package/node_modules/@shopify/ui-extensions-test-utils/dist/index.d.ts +3 -0
  16. package/node_modules/@shopify/ui-extensions-test-utils/dist/render.d.ts +2 -0
  17. package/node_modules/@shopify/ui-extensions-test-utils/dist/renderHook.d.ts +17 -0
  18. package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.d.ts +9 -0
  19. package/node_modules/@shopify/ui-extensions-test-utils/dist/withProviders.js +1 -0
  20. package/node_modules/@shopify/ui-extensions-test-utils/package.json +2 -3
  21. package/package.json +2 -4
  22. package/project.json +0 -2
  23. package/src/ExtensionServerClient/ExtensionServerClient.ts +2 -1
  24. package/src/ExtensionServerClient/types.ts +2 -0
  25. package/src/context/ExtensionServerProvider.tsx +2 -0
  26. package/src/state/actions/actions.ts +8 -1
  27. package/src/state/actions/types.ts +12 -1
  28. package/src/state/reducers/extensionServerReducer.test.ts +16 -2
  29. package/src/testing/extensions.ts +2 -2
  30. package/src/types.ts +3 -0
  31. package/src/utilities/replaceUpdated.ts +1 -0
  32. package/src/utilities/set.ts +1 -0
  33. package/node_modules/@types/node/LICENSE +0 -21
  34. package/node_modules/@types/node/README.md +0 -15
  35. package/node_modules/@types/node/assert/strict.d.ts +0 -8
  36. package/node_modules/@types/node/assert.d.ts +0 -985
  37. package/node_modules/@types/node/async_hooks.d.ts +0 -522
  38. package/node_modules/@types/node/buffer.d.ts +0 -2321
  39. package/node_modules/@types/node/child_process.d.ts +0 -1544
  40. package/node_modules/@types/node/cluster.d.ts +0 -432
  41. package/node_modules/@types/node/console.d.ts +0 -412
  42. package/node_modules/@types/node/constants.d.ts +0 -19
  43. package/node_modules/@types/node/crypto.d.ts +0 -4451
  44. package/node_modules/@types/node/dgram.d.ts +0 -586
  45. package/node_modules/@types/node/diagnostics_channel.d.ts +0 -192
  46. package/node_modules/@types/node/dns/promises.d.ts +0 -381
  47. package/node_modules/@types/node/dns.d.ts +0 -809
  48. package/node_modules/@types/node/dom-events.d.ts +0 -122
  49. package/node_modules/@types/node/domain.d.ts +0 -170
  50. package/node_modules/@types/node/events.d.ts +0 -803
  51. package/node_modules/@types/node/fs/promises.d.ts +0 -1205
  52. package/node_modules/@types/node/fs.d.ts +0 -4211
  53. package/node_modules/@types/node/globals.d.ts +0 -377
  54. package/node_modules/@types/node/globals.global.d.ts +0 -1
  55. package/node_modules/@types/node/http.d.ts +0 -1801
  56. package/node_modules/@types/node/http2.d.ts +0 -2386
  57. package/node_modules/@types/node/https.d.ts +0 -544
  58. package/node_modules/@types/node/index.d.ts +0 -88
  59. package/node_modules/@types/node/inspector.d.ts +0 -2739
  60. package/node_modules/@types/node/module.d.ts +0 -298
  61. package/node_modules/@types/node/net.d.ts +0 -913
  62. package/node_modules/@types/node/os.d.ts +0 -473
  63. package/node_modules/@types/node/package.json +0 -235
  64. package/node_modules/@types/node/path.d.ts +0 -191
  65. package/node_modules/@types/node/perf_hooks.d.ts +0 -626
  66. package/node_modules/@types/node/process.d.ts +0 -1531
  67. package/node_modules/@types/node/punycode.d.ts +0 -117
  68. package/node_modules/@types/node/querystring.d.ts +0 -141
  69. package/node_modules/@types/node/readline/promises.d.ts +0 -143
  70. package/node_modules/@types/node/readline.d.ts +0 -666
  71. package/node_modules/@types/node/repl.d.ts +0 -430
  72. package/node_modules/@types/node/stream/consumers.d.ts +0 -12
  73. package/node_modules/@types/node/stream/promises.d.ts +0 -83
  74. package/node_modules/@types/node/stream/web.d.ts +0 -336
  75. package/node_modules/@types/node/stream.d.ts +0 -1731
  76. package/node_modules/@types/node/string_decoder.d.ts +0 -67
  77. package/node_modules/@types/node/test.d.ts +0 -1113
  78. package/node_modules/@types/node/timers/promises.d.ts +0 -93
  79. package/node_modules/@types/node/timers.d.ts +0 -126
  80. package/node_modules/@types/node/tls.d.ts +0 -1203
  81. package/node_modules/@types/node/trace_events.d.ts +0 -171
  82. package/node_modules/@types/node/ts4.8/assert/strict.d.ts +0 -8
  83. package/node_modules/@types/node/ts4.8/assert.d.ts +0 -985
  84. package/node_modules/@types/node/ts4.8/async_hooks.d.ts +0 -522
  85. package/node_modules/@types/node/ts4.8/buffer.d.ts +0 -2321
  86. package/node_modules/@types/node/ts4.8/child_process.d.ts +0 -1544
  87. package/node_modules/@types/node/ts4.8/cluster.d.ts +0 -432
  88. package/node_modules/@types/node/ts4.8/console.d.ts +0 -412
  89. package/node_modules/@types/node/ts4.8/constants.d.ts +0 -19
  90. package/node_modules/@types/node/ts4.8/crypto.d.ts +0 -4450
  91. package/node_modules/@types/node/ts4.8/dgram.d.ts +0 -586
  92. package/node_modules/@types/node/ts4.8/diagnostics_channel.d.ts +0 -192
  93. package/node_modules/@types/node/ts4.8/dns/promises.d.ts +0 -381
  94. package/node_modules/@types/node/ts4.8/dns.d.ts +0 -809
  95. package/node_modules/@types/node/ts4.8/dom-events.d.ts +0 -122
  96. package/node_modules/@types/node/ts4.8/domain.d.ts +0 -170
  97. package/node_modules/@types/node/ts4.8/events.d.ts +0 -754
  98. package/node_modules/@types/node/ts4.8/fs/promises.d.ts +0 -1205
  99. package/node_modules/@types/node/ts4.8/fs.d.ts +0 -4211
  100. package/node_modules/@types/node/ts4.8/globals.d.ts +0 -377
  101. package/node_modules/@types/node/ts4.8/globals.global.d.ts +0 -1
  102. package/node_modules/@types/node/ts4.8/http.d.ts +0 -1801
  103. package/node_modules/@types/node/ts4.8/http2.d.ts +0 -2386
  104. package/node_modules/@types/node/ts4.8/https.d.ts +0 -544
  105. package/node_modules/@types/node/ts4.8/index.d.ts +0 -88
  106. package/node_modules/@types/node/ts4.8/inspector.d.ts +0 -2739
  107. package/node_modules/@types/node/ts4.8/module.d.ts +0 -298
  108. package/node_modules/@types/node/ts4.8/net.d.ts +0 -913
  109. package/node_modules/@types/node/ts4.8/os.d.ts +0 -473
  110. package/node_modules/@types/node/ts4.8/path.d.ts +0 -191
  111. package/node_modules/@types/node/ts4.8/perf_hooks.d.ts +0 -626
  112. package/node_modules/@types/node/ts4.8/process.d.ts +0 -1531
  113. package/node_modules/@types/node/ts4.8/punycode.d.ts +0 -117
  114. package/node_modules/@types/node/ts4.8/querystring.d.ts +0 -141
  115. package/node_modules/@types/node/ts4.8/readline/promises.d.ts +0 -143
  116. package/node_modules/@types/node/ts4.8/readline.d.ts +0 -666
  117. package/node_modules/@types/node/ts4.8/repl.d.ts +0 -430
  118. package/node_modules/@types/node/ts4.8/stream/consumers.d.ts +0 -12
  119. package/node_modules/@types/node/ts4.8/stream/promises.d.ts +0 -83
  120. package/node_modules/@types/node/ts4.8/stream/web.d.ts +0 -336
  121. package/node_modules/@types/node/ts4.8/stream.d.ts +0 -1731
  122. package/node_modules/@types/node/ts4.8/string_decoder.d.ts +0 -67
  123. package/node_modules/@types/node/ts4.8/test.d.ts +0 -1113
  124. package/node_modules/@types/node/ts4.8/timers/promises.d.ts +0 -93
  125. package/node_modules/@types/node/ts4.8/timers.d.ts +0 -126
  126. package/node_modules/@types/node/ts4.8/tls.d.ts +0 -1203
  127. package/node_modules/@types/node/ts4.8/trace_events.d.ts +0 -171
  128. package/node_modules/@types/node/ts4.8/tty.d.ts +0 -206
  129. package/node_modules/@types/node/ts4.8/url.d.ts +0 -937
  130. package/node_modules/@types/node/ts4.8/util.d.ts +0 -2075
  131. package/node_modules/@types/node/ts4.8/v8.d.ts +0 -541
  132. package/node_modules/@types/node/ts4.8/vm.d.ts +0 -667
  133. package/node_modules/@types/node/ts4.8/wasi.d.ts +0 -158
  134. package/node_modules/@types/node/ts4.8/worker_threads.d.ts +0 -692
  135. package/node_modules/@types/node/ts4.8/zlib.d.ts +0 -517
  136. package/node_modules/@types/node/tty.d.ts +0 -206
  137. package/node_modules/@types/node/url.d.ts +0 -937
  138. package/node_modules/@types/node/util.d.ts +0 -2075
  139. package/node_modules/@types/node/v8.d.ts +0 -541
  140. package/node_modules/@types/node/vm.d.ts +0 -667
  141. package/node_modules/@types/node/wasi.d.ts +0 -158
  142. package/node_modules/@types/node/worker_threads.d.ts +0 -692
  143. package/node_modules/@types/node/zlib.d.ts +0 -517
@@ -1,2321 +0,0 @@
1
- /**
2
- * `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
3
- * Node.js 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. Node.js 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 an uninitialized buffer of length 10.
23
- * // This is faster than calling Buffer.alloc() but the returned
24
- * // Buffer instance might contain old data that needs to be
25
- * // overwritten using fill(), write(), or other functions that fill the Buffer's
26
- * // contents.
27
- * const buf3 = Buffer.allocUnsafe(10);
28
- *
29
- * // Creates a Buffer containing the bytes [1, 2, 3].
30
- * const buf4 = Buffer.from([1, 2, 3]);
31
- *
32
- * // Creates a Buffer containing the bytes [1, 1, 1, 1] – the entries
33
- * // are all truncated using `(value & 255)` to fit into the range 0–255.
34
- * const buf5 = Buffer.from([257, 257.5, -255, '1']);
35
- *
36
- * // Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
37
- * // [0x74, 0xc3, 0xa9, 0x73, 0x74] (in hexadecimal notation)
38
- * // [116, 195, 169, 115, 116] (in decimal notation)
39
- * const buf6 = Buffer.from('tést');
40
- *
41
- * // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
42
- * const buf7 = Buffer.from('tést', 'latin1');
43
- * ```
44
- * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/buffer.js)
45
- */
46
- declare module "buffer" {
47
- import { BinaryLike } from "node:crypto";
48
- import { ReadableStream as WebReadableStream } from "node:stream/web";
49
- export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
50
- export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
51
- export const INSPECT_MAX_BYTES: number;
52
- export const kMaxLength: number;
53
- export const kStringMaxLength: number;
54
- export const constants: {
55
- MAX_LENGTH: number;
56
- MAX_STRING_LENGTH: number;
57
- };
58
- export type TranscodeEncoding = "ascii" | "utf8" | "utf16le" | "ucs2" | "latin1" | "binary";
59
- /**
60
- * Re-encodes the given `Buffer` or `Uint8Array` instance from one character
61
- * encoding to another. Returns a new `Buffer` instance.
62
- *
63
- * Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if
64
- * conversion from `fromEnc` to `toEnc` is not permitted.
65
- *
66
- * Encodings supported by `buffer.transcode()` are: `'ascii'`, `'utf8'`,`'utf16le'`, `'ucs2'`, `'latin1'`, and `'binary'`.
67
- *
68
- * The transcoding process will use substitution characters if a given byte
69
- * sequence cannot be adequately represented in the target encoding. For instance:
70
- *
71
- * ```js
72
- * import { Buffer, transcode } from 'buffer';
73
- *
74
- * const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
75
- * console.log(newBuf.toString('ascii'));
76
- * // Prints: '?'
77
- * ```
78
- *
79
- * Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
80
- * with `?` in the transcoded `Buffer`.
81
- * @since v7.1.0
82
- * @param source A `Buffer` or `Uint8Array` instance.
83
- * @param fromEnc The current encoding.
84
- * @param toEnc To target encoding.
85
- */
86
- export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
87
- export const SlowBuffer: {
88
- /** @deprecated since v6.0.0, use `Buffer.allocUnsafeSlow()` */
89
- new(size: number): Buffer;
90
- prototype: Buffer;
91
- };
92
- /**
93
- * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
94
- * a prior call to `URL.createObjectURL()`.
95
- * @since v16.7.0
96
- * @experimental
97
- * @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
98
- */
99
- export function resolveObjectURL(id: string): Blob | undefined;
100
- export { Buffer };
101
- /**
102
- * @experimental
103
- */
104
- export interface BlobOptions {
105
- /**
106
- * @default 'utf8'
107
- */
108
- encoding?: BufferEncoding | undefined;
109
- /**
110
- * The Blob content-type. The intent is for `type` to convey
111
- * the MIME media type of the data, however no validation of the type format
112
- * is performed.
113
- */
114
- type?: string | undefined;
115
- }
116
- /**
117
- * A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates immutable, raw data that can be safely shared across
118
- * multiple worker threads.
119
- * @since v15.7.0, v14.18.0
120
- */
121
- export class Blob {
122
- /**
123
- * The total size of the `Blob` in bytes.
124
- * @since v15.7.0, v14.18.0
125
- */
126
- readonly size: number;
127
- /**
128
- * The content-type of the `Blob`.
129
- * @since v15.7.0, v14.18.0
130
- */
131
- readonly type: string;
132
- /**
133
- * Creates a new `Blob` object containing a concatenation of the given sources.
134
- *
135
- * {ArrayBuffer}, {TypedArray}, {DataView}, and {Buffer} sources are copied into
136
- * the 'Blob' and can therefore be safely modified after the 'Blob' is created.
137
- *
138
- * String sources are also copied into the `Blob`.
139
- */
140
- constructor(sources: Array<BinaryLike | Blob>, options?: BlobOptions);
141
- /**
142
- * Returns a promise that fulfills with an [ArrayBuffer](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer) containing a copy of
143
- * the `Blob` data.
144
- * @since v15.7.0, v14.18.0
145
- */
146
- arrayBuffer(): Promise<ArrayBuffer>;
147
- /**
148
- * Creates and returns a new `Blob` containing a subset of this `Blob` objects
149
- * data. The original `Blob` is not altered.
150
- * @since v15.7.0, v14.18.0
151
- * @param start The starting index.
152
- * @param end The ending index.
153
- * @param type The content-type for the new `Blob`
154
- */
155
- slice(start?: number, end?: number, type?: string): Blob;
156
- /**
157
- * Returns a promise that fulfills with the contents of the `Blob` decoded as a
158
- * UTF-8 string.
159
- * @since v15.7.0, v14.18.0
160
- */
161
- text(): Promise<string>;
162
- /**
163
- * Returns a new (WHATWG) `ReadableStream` that allows the content of the `Blob` to be read.
164
- * @since v16.7.0
165
- */
166
- stream(): WebReadableStream;
167
- }
168
- export interface FileOptions {
169
- /**
170
- * One of either `'transparent'` or `'native'`. When set to `'native'`, line endings in string source parts will be
171
- * converted to the platform native line-ending as specified by `require('node:os').EOL`.
172
- */
173
- endings?: "native" | "transparent";
174
- /** The File content-type. */
175
- type?: string;
176
- /** The last modified date of the file. `Default`: Date.now(). */
177
- lastModified?: number;
178
- }
179
- /**
180
- * A [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) provides information about files.
181
- * @experimental
182
- * @since v18.13.0
183
- */
184
- export class File extends Blob {
185
- constructor(sources: Array<BinaryLike | Blob>, fileName: string, options?: FileOptions);
186
- /**
187
- * The name of the `File`.
188
- * @since v18.13.0
189
- */
190
- readonly name: string;
191
- /**
192
- * The last modified date of the `File`.
193
- * @since v18.13.0
194
- */
195
- readonly lastModified: number;
196
- }
197
- export import atob = globalThis.atob;
198
- export import btoa = globalThis.btoa;
199
-
200
- import { Blob as NodeBlob } from "buffer";
201
- // This conditional type will be the existing global Blob in a browser, or
202
- // the copy below in a Node environment.
203
- type __Blob = typeof globalThis extends { onmessage: any; Blob: any } ? {} : NodeBlob;
204
- global {
205
- namespace NodeJS {
206
- export { BufferEncoding };
207
- }
208
- // Buffer class
209
- type BufferEncoding =
210
- | "ascii"
211
- | "utf8"
212
- | "utf-8"
213
- | "utf16le"
214
- | "ucs2"
215
- | "ucs-2"
216
- | "base64"
217
- | "base64url"
218
- | "latin1"
219
- | "binary"
220
- | "hex";
221
- type WithImplicitCoercion<T> =
222
- | T
223
- | {
224
- valueOf(): T;
225
- };
226
- /**
227
- * Raw data is stored in instances of the Buffer class.
228
- * A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized.
229
- * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'
230
- */
231
- interface BufferConstructor {
232
- /**
233
- * Allocates a new buffer containing the given {str}.
234
- *
235
- * @param str String to store in buffer.
236
- * @param encoding encoding to use, optional. Default is 'utf8'
237
- * @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.
238
- */
239
- new(str: string, encoding?: BufferEncoding): Buffer;
240
- /**
241
- * Allocates a new buffer of {size} octets.
242
- *
243
- * @param size count of octets to allocate.
244
- * @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).
245
- */
246
- new(size: number): Buffer;
247
- /**
248
- * Allocates a new buffer containing the given {array} of octets.
249
- *
250
- * @param array The octets to store.
251
- * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
252
- */
253
- new(array: Uint8Array): Buffer;
254
- /**
255
- * Produces a Buffer backed by the same allocated memory as
256
- * the given {ArrayBuffer}/{SharedArrayBuffer}.
257
- *
258
- * @param arrayBuffer The ArrayBuffer with which to share memory.
259
- * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.
260
- */
261
- new(arrayBuffer: ArrayBuffer | SharedArrayBuffer): Buffer;
262
- /**
263
- * Allocates a new buffer containing the given {array} of octets.
264
- *
265
- * @param array The octets to store.
266
- * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.
267
- */
268
- new(array: readonly any[]): Buffer;
269
- /**
270
- * Copies the passed {buffer} data onto a new {Buffer} instance.
271
- *
272
- * @param buffer The buffer to copy.
273
- * @deprecated since v10.0.0 - Use `Buffer.from(buffer)` instead.
274
- */
275
- new(buffer: Buffer): Buffer;
276
- /**
277
- * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.
278
- * Array entries outside that range will be truncated to fit into it.
279
- *
280
- * ```js
281
- * import { Buffer } from 'buffer';
282
- *
283
- * // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.
284
- * const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);
285
- * ```
286
- *
287
- * A `TypeError` will be thrown if `array` is not an `Array` or another type
288
- * appropriate for `Buffer.from()` variants.
289
- *
290
- * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal`Buffer` pool like `Buffer.allocUnsafe()` does.
291
- * @since v5.10.0
292
- */
293
- from(
294
- arrayBuffer: WithImplicitCoercion<ArrayBuffer | SharedArrayBuffer>,
295
- byteOffset?: number,
296
- length?: number,
297
- ): Buffer;
298
- /**
299
- * Creates a new Buffer using the passed {data}
300
- * @param data data to create a new Buffer
301
- */
302
- from(data: Uint8Array | readonly number[]): Buffer;
303
- from(data: WithImplicitCoercion<Uint8Array | readonly number[] | string>): Buffer;
304
- /**
305
- * Creates a new Buffer containing the given JavaScript string {str}.
306
- * If provided, the {encoding} parameter identifies the character encoding.
307
- * If not provided, {encoding} defaults to 'utf8'.
308
- */
309
- from(
310
- str:
311
- | WithImplicitCoercion<string>
312
- | {
313
- [Symbol.toPrimitive](hint: "string"): string;
314
- },
315
- encoding?: BufferEncoding,
316
- ): Buffer;
317
- /**
318
- * Creates a new Buffer using the passed {data}
319
- * @param values to create a new Buffer
320
- */
321
- of(...items: number[]): Buffer;
322
- /**
323
- * Returns `true` if `obj` is a `Buffer`, `false` otherwise.
324
- *
325
- * ```js
326
- * import { Buffer } from 'buffer';
327
- *
328
- * Buffer.isBuffer(Buffer.alloc(10)); // true
329
- * Buffer.isBuffer(Buffer.from('foo')); // true
330
- * Buffer.isBuffer('a string'); // false
331
- * Buffer.isBuffer([]); // false
332
- * Buffer.isBuffer(new Uint8Array(1024)); // false
333
- * ```
334
- * @since v0.1.101
335
- */
336
- isBuffer(obj: any): obj is Buffer;
337
- /**
338
- * Returns `true` if `encoding` is the name of a supported character encoding,
339
- * or `false` otherwise.
340
- *
341
- * ```js
342
- * import { Buffer } from 'buffer';
343
- *
344
- * console.log(Buffer.isEncoding('utf8'));
345
- * // Prints: true
346
- *
347
- * console.log(Buffer.isEncoding('hex'));
348
- * // Prints: true
349
- *
350
- * console.log(Buffer.isEncoding('utf/8'));
351
- * // Prints: false
352
- *
353
- * console.log(Buffer.isEncoding(''));
354
- * // Prints: false
355
- * ```
356
- * @since v0.9.1
357
- * @param encoding A character encoding name to check.
358
- */
359
- isEncoding(encoding: string): encoding is BufferEncoding;
360
- /**
361
- * Returns the byte length of a string when encoded using `encoding`.
362
- * 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
363
- * for the encoding that is used to convert the string into bytes.
364
- *
365
- * For `'base64'`, `'base64url'`, and `'hex'`, this function assumes valid input.
366
- * For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
367
- * return value might be greater than the length of a `Buffer` created from the
368
- * string.
369
- *
370
- * ```js
371
- * import { Buffer } from 'buffer';
372
- *
373
- * const str = '\u00bd + \u00bc = \u00be';
374
- *
375
- * console.log(`${str}: ${str.length} characters, ` +
376
- * `${Buffer.byteLength(str, 'utf8')} bytes`);
377
- * // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
378
- * ```
379
- *
380
- * When `string` is a
381
- * `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/-
382
- * Reference/Global_Objects/TypedArray)/[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)/[`SharedArrayBuffer`](https://develop-
383
- * er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by `.byteLength`is returned.
384
- * @since v0.1.90
385
- * @param string A value to calculate the length of.
386
- * @param [encoding='utf8'] If `string` is a string, this is its encoding.
387
- * @return The number of bytes contained within `string`.
388
- */
389
- byteLength(
390
- string: string | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
391
- encoding?: BufferEncoding,
392
- ): number;
393
- /**
394
- * Returns a new `Buffer` which is the result of concatenating all the `Buffer`instances in the `list` together.
395
- *
396
- * If the list has no items, or if the `totalLength` is 0, then a new zero-length`Buffer` is returned.
397
- *
398
- * If `totalLength` is not provided, it is calculated from the `Buffer` instances
399
- * in `list` by adding their lengths.
400
- *
401
- * If `totalLength` is provided, it is coerced to an unsigned integer. If the
402
- * combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is
403
- * truncated to `totalLength`.
404
- *
405
- * ```js
406
- * import { Buffer } from 'buffer';
407
- *
408
- * // Create a single `Buffer` from a list of three `Buffer` instances.
409
- *
410
- * const buf1 = Buffer.alloc(10);
411
- * const buf2 = Buffer.alloc(14);
412
- * const buf3 = Buffer.alloc(18);
413
- * const totalLength = buf1.length + buf2.length + buf3.length;
414
- *
415
- * console.log(totalLength);
416
- * // Prints: 42
417
- *
418
- * const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);
419
- *
420
- * console.log(bufA);
421
- * // Prints: <Buffer 00 00 00 00 ...>
422
- * console.log(bufA.length);
423
- * // Prints: 42
424
- * ```
425
- *
426
- * `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.
427
- * @since v0.7.11
428
- * @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.
429
- * @param totalLength Total length of the `Buffer` instances in `list` when concatenated.
430
- */
431
- concat(list: readonly Uint8Array[], totalLength?: number): Buffer;
432
- /**
433
- * Copies the underlying memory of `view` into a new `Buffer`.
434
- * @since v18.16.0
435
- * @param view The `TypedArray` to copy.
436
- * @param offset The starting offset within `view`.
437
- * @param length The number of elements from `view` to copy.
438
- */
439
- copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer;
440
- /**
441
- * Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of`Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`.
442
- *
443
- * ```js
444
- * import { Buffer } from 'buffer';
445
- *
446
- * const buf1 = Buffer.from('1234');
447
- * const buf2 = Buffer.from('0123');
448
- * const arr = [buf1, buf2];
449
- *
450
- * console.log(arr.sort(Buffer.compare));
451
- * // Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
452
- * // (This result is equal to: [buf2, buf1].)
453
- * ```
454
- * @since v0.11.13
455
- * @return Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.
456
- */
457
- compare(buf1: Uint8Array, buf2: Uint8Array): -1 | 0 | 1;
458
- /**
459
- * Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.
460
- *
461
- * ```js
462
- * import { Buffer } from 'buffer';
463
- *
464
- * const buf = Buffer.alloc(5);
465
- *
466
- * console.log(buf);
467
- * // Prints: <Buffer 00 00 00 00 00>
468
- * ```
469
- *
470
- * If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown.
471
- *
472
- * If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.
473
- *
474
- * ```js
475
- * import { Buffer } from 'buffer';
476
- *
477
- * const buf = Buffer.alloc(5, 'a');
478
- *
479
- * console.log(buf);
480
- * // Prints: <Buffer 61 61 61 61 61>
481
- * ```
482
- *
483
- * If both `fill` and `encoding` are specified, the allocated `Buffer` will be
484
- * initialized by calling `buf.fill(fill, encoding)`.
485
- *
486
- * ```js
487
- * import { Buffer } from 'buffer';
488
- *
489
- * const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');
490
- *
491
- * console.log(buf);
492
- * // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>
493
- * ```
494
- *
495
- * Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance
496
- * contents will never contain sensitive data from previous allocations, including
497
- * data that might not have been allocated for `Buffer`s.
498
- *
499
- * A `TypeError` will be thrown if `size` is not a number.
500
- * @since v5.10.0
501
- * @param size The desired length of the new `Buffer`.
502
- * @param [fill=0] A value to pre-fill the new `Buffer` with.
503
- * @param [encoding='utf8'] If `fill` is a string, this is its encoding.
504
- */
505
- alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer;
506
- /**
507
- * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown.
508
- *
509
- * The underlying memory for `Buffer` instances created in this way is _not_
510
- * _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes.
511
- *
512
- * ```js
513
- * import { Buffer } from 'buffer';
514
- *
515
- * const buf = Buffer.allocUnsafe(10);
516
- *
517
- * console.log(buf);
518
- * // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>
519
- *
520
- * buf.fill(0);
521
- *
522
- * console.log(buf);
523
- * // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>
524
- * ```
525
- *
526
- * A `TypeError` will be thrown if `size` is not a number.
527
- *
528
- * The `Buffer` module pre-allocates an internal `Buffer` instance of
529
- * size `Buffer.poolSize` that is used as a pool for the fast allocation of new`Buffer` instances created using `Buffer.allocUnsafe()`,`Buffer.from(array)`, `Buffer.concat()`, and the
530
- * deprecated`new Buffer(size)` constructor only when `size` is less than or equal
531
- * to `Buffer.poolSize >> 1` (floor of `Buffer.poolSize` divided by two).
532
- *
533
- * Use of this pre-allocated internal memory pool is a key difference between
534
- * calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.
535
- * Specifically, `Buffer.alloc(size, fill)` will _never_ use the internal `Buffer`pool, while `Buffer.allocUnsafe(size).fill(fill)`_will_ use the internal`Buffer` pool if `size` is less
536
- * than or equal to half `Buffer.poolSize`. The
537
- * difference is subtle but can be important when an application requires the
538
- * additional performance that `Buffer.allocUnsafe()` provides.
539
- * @since v5.10.0
540
- * @param size The desired length of the new `Buffer`.
541
- */
542
- allocUnsafe(size: number): Buffer;
543
- /**
544
- * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_INVALID_ARG_VALUE` is thrown. A zero-length `Buffer` is created
545
- * if `size` is 0.
546
- *
547
- * The underlying memory for `Buffer` instances created in this way is _not_
548
- * _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize
549
- * such `Buffer` instances with zeroes.
550
- *
551
- * When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,
552
- * allocations under 4 KB are sliced from a single pre-allocated `Buffer`. This
553
- * allows applications to avoid the garbage collection overhead of creating many
554
- * individually allocated `Buffer` instances. This approach improves both
555
- * performance and memory usage by eliminating the need to track and clean up as
556
- * many individual `ArrayBuffer` objects.
557
- *
558
- * However, in the case where a developer may need to retain a small chunk of
559
- * memory from a pool for an indeterminate amount of time, it may be appropriate
560
- * to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and
561
- * then copying out the relevant bits.
562
- *
563
- * ```js
564
- * import { Buffer } from 'buffer';
565
- *
566
- * // Need to keep around a few small chunks of memory.
567
- * const store = [];
568
- *
569
- * socket.on('readable', () => {
570
- * let data;
571
- * while (null !== (data = readable.read())) {
572
- * // Allocate for retained data.
573
- * const sb = Buffer.allocUnsafeSlow(10);
574
- *
575
- * // Copy the data into the new allocation.
576
- * data.copy(sb, 0, 0, 10);
577
- *
578
- * store.push(sb);
579
- * }
580
- * });
581
- * ```
582
- *
583
- * A `TypeError` will be thrown if `size` is not a number.
584
- * @since v5.12.0
585
- * @param size The desired length of the new `Buffer`.
586
- */
587
- allocUnsafeSlow(size: number): Buffer;
588
- /**
589
- * This is the size (in bytes) of pre-allocated internal `Buffer` instances used
590
- * for pooling. This value may be modified.
591
- * @since v0.11.3
592
- */
593
- poolSize: number;
594
- }
595
- interface Buffer extends Uint8Array {
596
- /**
597
- * Writes `string` to `buf` at `offset` according to the character encoding in`encoding`. The `length` parameter is the number of bytes to write. If `buf` did
598
- * not contain enough space to fit the entire string, only part of `string` will be
599
- * written. However, partially encoded characters will not be written.
600
- *
601
- * ```js
602
- * import { Buffer } from 'buffer';
603
- *
604
- * const buf = Buffer.alloc(256);
605
- *
606
- * const len = buf.write('\u00bd + \u00bc = \u00be', 0);
607
- *
608
- * console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
609
- * // Prints: 12 bytes: ½ + ¼ = ¾
610
- *
611
- * const buffer = Buffer.alloc(10);
612
- *
613
- * const length = buffer.write('abcd', 8);
614
- *
615
- * console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
616
- * // Prints: 2 bytes : ab
617
- * ```
618
- * @since v0.1.90
619
- * @param string String to write to `buf`.
620
- * @param [offset=0] Number of bytes to skip before starting to write `string`.
621
- * @param [length=buf.length - offset] Maximum number of bytes to write (written bytes will not exceed `buf.length - offset`).
622
- * @param [encoding='utf8'] The character encoding of `string`.
623
- * @return Number of bytes written.
624
- */
625
- write(string: string, encoding?: BufferEncoding): number;
626
- write(string: string, offset: number, encoding?: BufferEncoding): number;
627
- write(string: string, offset: number, length: number, encoding?: BufferEncoding): number;
628
- /**
629
- * Decodes `buf` to a string according to the specified character encoding in`encoding`. `start` and `end` may be passed to decode only a subset of `buf`.
630
- *
631
- * If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
632
- * then each invalid byte is replaced with the replacement character `U+FFFD`.
633
- *
634
- * The maximum length of a string instance (in UTF-16 code units) is available
635
- * as {@link constants.MAX_STRING_LENGTH}.
636
- *
637
- * ```js
638
- * import { Buffer } from 'buffer';
639
- *
640
- * const buf1 = Buffer.allocUnsafe(26);
641
- *
642
- * for (let i = 0; i < 26; i++) {
643
- * // 97 is the decimal ASCII value for 'a'.
644
- * buf1[i] = i + 97;
645
- * }
646
- *
647
- * console.log(buf1.toString('utf8'));
648
- * // Prints: abcdefghijklmnopqrstuvwxyz
649
- * console.log(buf1.toString('utf8', 0, 5));
650
- * // Prints: abcde
651
- *
652
- * const buf2 = Buffer.from('tést');
653
- *
654
- * console.log(buf2.toString('hex'));
655
- * // Prints: 74c3a97374
656
- * console.log(buf2.toString('utf8', 0, 3));
657
- * // Prints: té
658
- * console.log(buf2.toString(undefined, 0, 3));
659
- * // Prints: té
660
- * ```
661
- * @since v0.1.90
662
- * @param [encoding='utf8'] The character encoding to use.
663
- * @param [start=0] The byte offset to start decoding at.
664
- * @param [end=buf.length] The byte offset to stop decoding at (not inclusive).
665
- */
666
- toString(encoding?: BufferEncoding, start?: number, end?: number): string;
667
- /**
668
- * Returns a JSON representation of `buf`. [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) implicitly calls
669
- * this function when stringifying a `Buffer` instance.
670
- *
671
- * `Buffer.from()` accepts objects in the format returned from this method.
672
- * In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`.
673
- *
674
- * ```js
675
- * import { Buffer } from 'buffer';
676
- *
677
- * const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
678
- * const json = JSON.stringify(buf);
679
- *
680
- * console.log(json);
681
- * // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
682
- *
683
- * const copy = JSON.parse(json, (key, value) => {
684
- * return value &#x26;&#x26; value.type === 'Buffer' ?
685
- * Buffer.from(value) :
686
- * value;
687
- * });
688
- *
689
- * console.log(copy);
690
- * // Prints: <Buffer 01 02 03 04 05>
691
- * ```
692
- * @since v0.9.2
693
- */
694
- toJSON(): {
695
- type: "Buffer";
696
- data: number[];
697
- };
698
- /**
699
- * Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes,`false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`.
700
- *
701
- * ```js
702
- * import { Buffer } from 'buffer';
703
- *
704
- * const buf1 = Buffer.from('ABC');
705
- * const buf2 = Buffer.from('414243', 'hex');
706
- * const buf3 = Buffer.from('ABCD');
707
- *
708
- * console.log(buf1.equals(buf2));
709
- * // Prints: true
710
- * console.log(buf1.equals(buf3));
711
- * // Prints: false
712
- * ```
713
- * @since v0.11.13
714
- * @param otherBuffer A `Buffer` or {@link Uint8Array} with which to compare `buf`.
715
- */
716
- equals(otherBuffer: Uint8Array): boolean;
717
- /**
718
- * Compares `buf` with `target` and returns a number indicating whether `buf`comes before, after, or is the same as `target` in sort order.
719
- * Comparison is based on the actual sequence of bytes in each `Buffer`.
720
- *
721
- * * `0` is returned if `target` is the same as `buf`
722
- * * `1` is returned if `target` should come _before_`buf` when sorted.
723
- * * `-1` is returned if `target` should come _after_`buf` when sorted.
724
- *
725
- * ```js
726
- * import { Buffer } from 'buffer';
727
- *
728
- * const buf1 = Buffer.from('ABC');
729
- * const buf2 = Buffer.from('BCD');
730
- * const buf3 = Buffer.from('ABCD');
731
- *
732
- * console.log(buf1.compare(buf1));
733
- * // Prints: 0
734
- * console.log(buf1.compare(buf2));
735
- * // Prints: -1
736
- * console.log(buf1.compare(buf3));
737
- * // Prints: -1
738
- * console.log(buf2.compare(buf1));
739
- * // Prints: 1
740
- * console.log(buf2.compare(buf3));
741
- * // Prints: 1
742
- * console.log([buf1, buf2, buf3].sort(Buffer.compare));
743
- * // Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
744
- * // (This result is equal to: [buf1, buf3, buf2].)
745
- * ```
746
- *
747
- * The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd`arguments can be used to limit the comparison to specific ranges within `target`and `buf` respectively.
748
- *
749
- * ```js
750
- * import { Buffer } from 'buffer';
751
- *
752
- * const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
753
- * const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
754
- *
755
- * console.log(buf1.compare(buf2, 5, 9, 0, 4));
756
- * // Prints: 0
757
- * console.log(buf1.compare(buf2, 0, 6, 4));
758
- * // Prints: -1
759
- * console.log(buf1.compare(buf2, 5, 6, 5));
760
- * // Prints: 1
761
- * ```
762
- *
763
- * `ERR_OUT_OF_RANGE` is thrown if `targetStart < 0`, `sourceStart < 0`,`targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`.
764
- * @since v0.11.13
765
- * @param target A `Buffer` or {@link Uint8Array} with which to compare `buf`.
766
- * @param [targetStart=0] The offset within `target` at which to begin comparison.
767
- * @param [targetEnd=target.length] The offset within `target` at which to end comparison (not inclusive).
768
- * @param [sourceStart=0] The offset within `buf` at which to begin comparison.
769
- * @param [sourceEnd=buf.length] The offset within `buf` at which to end comparison (not inclusive).
770
- */
771
- compare(
772
- target: Uint8Array,
773
- targetStart?: number,
774
- targetEnd?: number,
775
- sourceStart?: number,
776
- sourceEnd?: number,
777
- ): -1 | 0 | 1;
778
- /**
779
- * Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
780
- *
781
- * [`TypedArray.prototype.set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set) performs the same operation, and is available
782
- * for all TypedArrays, including Node.js `Buffer`s, although it takes
783
- * different function arguments.
784
- *
785
- * ```js
786
- * import { Buffer } from 'buffer';
787
- *
788
- * // Create two `Buffer` instances.
789
- * const buf1 = Buffer.allocUnsafe(26);
790
- * const buf2 = Buffer.allocUnsafe(26).fill('!');
791
- *
792
- * for (let i = 0; i < 26; i++) {
793
- * // 97 is the decimal ASCII value for 'a'.
794
- * buf1[i] = i + 97;
795
- * }
796
- *
797
- * // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
798
- * buf1.copy(buf2, 8, 16, 20);
799
- * // This is equivalent to:
800
- * // buf2.set(buf1.subarray(16, 20), 8);
801
- *
802
- * console.log(buf2.toString('ascii', 0, 25));
803
- * // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
804
- * ```
805
- *
806
- * ```js
807
- * import { Buffer } from 'buffer';
808
- *
809
- * // Create a `Buffer` and copy data from one region to an overlapping region
810
- * // within the same `Buffer`.
811
- *
812
- * const buf = Buffer.allocUnsafe(26);
813
- *
814
- * for (let i = 0; i < 26; i++) {
815
- * // 97 is the decimal ASCII value for 'a'.
816
- * buf[i] = i + 97;
817
- * }
818
- *
819
- * buf.copy(buf, 0, 4, 10);
820
- *
821
- * console.log(buf.toString());
822
- * // Prints: efghijghijklmnopqrstuvwxyz
823
- * ```
824
- * @since v0.1.90
825
- * @param target A `Buffer` or {@link Uint8Array} to copy into.
826
- * @param [targetStart=0] The offset within `target` at which to begin writing.
827
- * @param [sourceStart=0] The offset within `buf` from which to begin copying.
828
- * @param [sourceEnd=buf.length] The offset within `buf` at which to stop copying (not inclusive).
829
- * @return The number of bytes copied.
830
- */
831
- copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
832
- /**
833
- * Returns a new `Buffer` that references the same memory as the original, but
834
- * offset and cropped by the `start` and `end` indices.
835
- *
836
- * This method is not compatible with the `Uint8Array.prototype.slice()`,
837
- * which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.
838
- *
839
- * ```js
840
- * import { Buffer } from 'buffer';
841
- *
842
- * const buf = Buffer.from('buffer');
843
- *
844
- * const copiedBuf = Uint8Array.prototype.slice.call(buf);
845
- * copiedBuf[0]++;
846
- * console.log(copiedBuf.toString());
847
- * // Prints: cuffer
848
- *
849
- * console.log(buf.toString());
850
- * // Prints: buffer
851
- *
852
- * // With buf.slice(), the original buffer is modified.
853
- * const notReallyCopiedBuf = buf.slice();
854
- * notReallyCopiedBuf[0]++;
855
- * console.log(notReallyCopiedBuf.toString());
856
- * // Prints: cuffer
857
- * console.log(buf.toString());
858
- * // Also prints: cuffer (!)
859
- * ```
860
- * @since v0.3.0
861
- * @deprecated Use `subarray` instead.
862
- * @param [start=0] Where the new `Buffer` will start.
863
- * @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
864
- */
865
- slice(start?: number, end?: number): Buffer;
866
- /**
867
- * Returns a new `Buffer` that references the same memory as the original, but
868
- * offset and cropped by the `start` and `end` indices.
869
- *
870
- * Specifying `end` greater than `buf.length` will return the same result as
871
- * that of `end` equal to `buf.length`.
872
- *
873
- * This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).
874
- *
875
- * Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.
876
- *
877
- * ```js
878
- * import { Buffer } from 'buffer';
879
- *
880
- * // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte
881
- * // from the original `Buffer`.
882
- *
883
- * const buf1 = Buffer.allocUnsafe(26);
884
- *
885
- * for (let i = 0; i < 26; i++) {
886
- * // 97 is the decimal ASCII value for 'a'.
887
- * buf1[i] = i + 97;
888
- * }
889
- *
890
- * const buf2 = buf1.subarray(0, 3);
891
- *
892
- * console.log(buf2.toString('ascii', 0, buf2.length));
893
- * // Prints: abc
894
- *
895
- * buf1[0] = 33;
896
- *
897
- * console.log(buf2.toString('ascii', 0, buf2.length));
898
- * // Prints: !bc
899
- * ```
900
- *
901
- * Specifying negative indexes causes the slice to be generated relative to the
902
- * end of `buf` rather than the beginning.
903
- *
904
- * ```js
905
- * import { Buffer } from 'buffer';
906
- *
907
- * const buf = Buffer.from('buffer');
908
- *
909
- * console.log(buf.subarray(-6, -1).toString());
910
- * // Prints: buffe
911
- * // (Equivalent to buf.subarray(0, 5).)
912
- *
913
- * console.log(buf.subarray(-6, -2).toString());
914
- * // Prints: buff
915
- * // (Equivalent to buf.subarray(0, 4).)
916
- *
917
- * console.log(buf.subarray(-5, -2).toString());
918
- * // Prints: uff
919
- * // (Equivalent to buf.subarray(1, 4).)
920
- * ```
921
- * @since v3.0.0
922
- * @param [start=0] Where the new `Buffer` will start.
923
- * @param [end=buf.length] Where the new `Buffer` will end (not inclusive).
924
- */
925
- subarray(start?: number, end?: number): Buffer;
926
- /**
927
- * Writes `value` to `buf` at the specified `offset` as big-endian.
928
- *
929
- * `value` is interpreted and written as a two's complement signed integer.
930
- *
931
- * ```js
932
- * import { Buffer } from 'buffer';
933
- *
934
- * const buf = Buffer.allocUnsafe(8);
935
- *
936
- * buf.writeBigInt64BE(0x0102030405060708n, 0);
937
- *
938
- * console.log(buf);
939
- * // Prints: <Buffer 01 02 03 04 05 06 07 08>
940
- * ```
941
- * @since v12.0.0, v10.20.0
942
- * @param value Number to be written to `buf`.
943
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
944
- * @return `offset` plus the number of bytes written.
945
- */
946
- writeBigInt64BE(value: bigint, offset?: number): number;
947
- /**
948
- * Writes `value` to `buf` at the specified `offset` as little-endian.
949
- *
950
- * `value` is interpreted and written as a two's complement signed integer.
951
- *
952
- * ```js
953
- * import { Buffer } from 'buffer';
954
- *
955
- * const buf = Buffer.allocUnsafe(8);
956
- *
957
- * buf.writeBigInt64LE(0x0102030405060708n, 0);
958
- *
959
- * console.log(buf);
960
- * // Prints: <Buffer 08 07 06 05 04 03 02 01>
961
- * ```
962
- * @since v12.0.0, v10.20.0
963
- * @param value Number to be written to `buf`.
964
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
965
- * @return `offset` plus the number of bytes written.
966
- */
967
- writeBigInt64LE(value: bigint, offset?: number): number;
968
- /**
969
- * Writes `value` to `buf` at the specified `offset` as big-endian.
970
- *
971
- * This function is also available under the `writeBigUint64BE` alias.
972
- *
973
- * ```js
974
- * import { Buffer } from 'buffer';
975
- *
976
- * const buf = Buffer.allocUnsafe(8);
977
- *
978
- * buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
979
- *
980
- * console.log(buf);
981
- * // Prints: <Buffer de ca fa fe ca ce fa de>
982
- * ```
983
- * @since v12.0.0, v10.20.0
984
- * @param value Number to be written to `buf`.
985
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
986
- * @return `offset` plus the number of bytes written.
987
- */
988
- writeBigUInt64BE(value: bigint, offset?: number): number;
989
- /**
990
- * @alias Buffer.writeBigUInt64BE
991
- * @since v14.10.0, v12.19.0
992
- */
993
- writeBigUint64BE(value: bigint, offset?: number): number;
994
- /**
995
- * Writes `value` to `buf` at the specified `offset` as little-endian
996
- *
997
- * ```js
998
- * import { Buffer } from 'buffer';
999
- *
1000
- * const buf = Buffer.allocUnsafe(8);
1001
- *
1002
- * buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
1003
- *
1004
- * console.log(buf);
1005
- * // Prints: <Buffer de fa ce ca fe fa ca de>
1006
- * ```
1007
- *
1008
- * This function is also available under the `writeBigUint64LE` alias.
1009
- * @since v12.0.0, v10.20.0
1010
- * @param value Number to be written to `buf`.
1011
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
1012
- * @return `offset` plus the number of bytes written.
1013
- */
1014
- writeBigUInt64LE(value: bigint, offset?: number): number;
1015
- /**
1016
- * @alias Buffer.writeBigUInt64LE
1017
- * @since v14.10.0, v12.19.0
1018
- */
1019
- writeBigUint64LE(value: bigint, offset?: number): number;
1020
- /**
1021
- * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
1022
- * when `value` is anything other than an unsigned integer.
1023
- *
1024
- * This function is also available under the `writeUintLE` alias.
1025
- *
1026
- * ```js
1027
- * import { Buffer } from 'buffer';
1028
- *
1029
- * const buf = Buffer.allocUnsafe(6);
1030
- *
1031
- * buf.writeUIntLE(0x1234567890ab, 0, 6);
1032
- *
1033
- * console.log(buf);
1034
- * // Prints: <Buffer ab 90 78 56 34 12>
1035
- * ```
1036
- * @since v0.5.5
1037
- * @param value Number to be written to `buf`.
1038
- * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
1039
- * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
1040
- * @return `offset` plus the number of bytes written.
1041
- */
1042
- writeUIntLE(value: number, offset: number, byteLength: number): number;
1043
- /**
1044
- * @alias Buffer.writeUIntLE
1045
- * @since v14.9.0, v12.19.0
1046
- */
1047
- writeUintLE(value: number, offset: number, byteLength: number): number;
1048
- /**
1049
- * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
1050
- * when `value` is anything other than an unsigned integer.
1051
- *
1052
- * This function is also available under the `writeUintBE` alias.
1053
- *
1054
- * ```js
1055
- * import { Buffer } from 'buffer';
1056
- *
1057
- * const buf = Buffer.allocUnsafe(6);
1058
- *
1059
- * buf.writeUIntBE(0x1234567890ab, 0, 6);
1060
- *
1061
- * console.log(buf);
1062
- * // Prints: <Buffer 12 34 56 78 90 ab>
1063
- * ```
1064
- * @since v0.5.5
1065
- * @param value Number to be written to `buf`.
1066
- * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
1067
- * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
1068
- * @return `offset` plus the number of bytes written.
1069
- */
1070
- writeUIntBE(value: number, offset: number, byteLength: number): number;
1071
- /**
1072
- * @alias Buffer.writeUIntBE
1073
- * @since v14.9.0, v12.19.0
1074
- */
1075
- writeUintBE(value: number, offset: number, byteLength: number): number;
1076
- /**
1077
- * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
1078
- * when `value` is anything other than a signed integer.
1079
- *
1080
- * ```js
1081
- * import { Buffer } from 'buffer';
1082
- *
1083
- * const buf = Buffer.allocUnsafe(6);
1084
- *
1085
- * buf.writeIntLE(0x1234567890ab, 0, 6);
1086
- *
1087
- * console.log(buf);
1088
- * // Prints: <Buffer ab 90 78 56 34 12>
1089
- * ```
1090
- * @since v0.11.15
1091
- * @param value Number to be written to `buf`.
1092
- * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
1093
- * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
1094
- * @return `offset` plus the number of bytes written.
1095
- */
1096
- writeIntLE(value: number, offset: number, byteLength: number): number;
1097
- /**
1098
- * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined when`value` is anything other than a
1099
- * signed integer.
1100
- *
1101
- * ```js
1102
- * import { Buffer } from 'buffer';
1103
- *
1104
- * const buf = Buffer.allocUnsafe(6);
1105
- *
1106
- * buf.writeIntBE(0x1234567890ab, 0, 6);
1107
- *
1108
- * console.log(buf);
1109
- * // Prints: <Buffer 12 34 56 78 90 ab>
1110
- * ```
1111
- * @since v0.11.15
1112
- * @param value Number to be written to `buf`.
1113
- * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
1114
- * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
1115
- * @return `offset` plus the number of bytes written.
1116
- */
1117
- writeIntBE(value: number, offset: number, byteLength: number): number;
1118
- /**
1119
- * Reads an unsigned, big-endian 64-bit integer from `buf` at the specified`offset`.
1120
- *
1121
- * This function is also available under the `readBigUint64BE` alias.
1122
- *
1123
- * ```js
1124
- * import { Buffer } from 'buffer';
1125
- *
1126
- * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
1127
- *
1128
- * console.log(buf.readBigUInt64BE(0));
1129
- * // Prints: 4294967295n
1130
- * ```
1131
- * @since v12.0.0, v10.20.0
1132
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
1133
- */
1134
- readBigUInt64BE(offset?: number): bigint;
1135
- /**
1136
- * @alias Buffer.readBigUInt64BE
1137
- * @since v14.10.0, v12.19.0
1138
- */
1139
- readBigUint64BE(offset?: number): bigint;
1140
- /**
1141
- * Reads an unsigned, little-endian 64-bit integer from `buf` at the specified`offset`.
1142
- *
1143
- * This function is also available under the `readBigUint64LE` alias.
1144
- *
1145
- * ```js
1146
- * import { Buffer } from 'buffer';
1147
- *
1148
- * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
1149
- *
1150
- * console.log(buf.readBigUInt64LE(0));
1151
- * // Prints: 18446744069414584320n
1152
- * ```
1153
- * @since v12.0.0, v10.20.0
1154
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
1155
- */
1156
- readBigUInt64LE(offset?: number): bigint;
1157
- /**
1158
- * @alias Buffer.readBigUInt64LE
1159
- * @since v14.10.0, v12.19.0
1160
- */
1161
- readBigUint64LE(offset?: number): bigint;
1162
- /**
1163
- * Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`.
1164
- *
1165
- * Integers read from a `Buffer` are interpreted as two's complement signed
1166
- * values.
1167
- * @since v12.0.0, v10.20.0
1168
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
1169
- */
1170
- readBigInt64BE(offset?: number): bigint;
1171
- /**
1172
- * Reads a signed, little-endian 64-bit integer from `buf` at the specified`offset`.
1173
- *
1174
- * Integers read from a `Buffer` are interpreted as two's complement signed
1175
- * values.
1176
- * @since v12.0.0, v10.20.0
1177
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
1178
- */
1179
- readBigInt64LE(offset?: number): bigint;
1180
- /**
1181
- * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as an unsigned, little-endian integer supporting
1182
- * up to 48 bits of accuracy.
1183
- *
1184
- * This function is also available under the `readUintLE` alias.
1185
- *
1186
- * ```js
1187
- * import { Buffer } from 'buffer';
1188
- *
1189
- * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1190
- *
1191
- * console.log(buf.readUIntLE(0, 6).toString(16));
1192
- * // Prints: ab9078563412
1193
- * ```
1194
- * @since v0.11.15
1195
- * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
1196
- * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
1197
- */
1198
- readUIntLE(offset: number, byteLength: number): number;
1199
- /**
1200
- * @alias Buffer.readUIntLE
1201
- * @since v14.9.0, v12.19.0
1202
- */
1203
- readUintLE(offset: number, byteLength: number): number;
1204
- /**
1205
- * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as an unsigned big-endian integer supporting
1206
- * up to 48 bits of accuracy.
1207
- *
1208
- * This function is also available under the `readUintBE` alias.
1209
- *
1210
- * ```js
1211
- * import { Buffer } from 'buffer';
1212
- *
1213
- * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1214
- *
1215
- * console.log(buf.readUIntBE(0, 6).toString(16));
1216
- * // Prints: 1234567890ab
1217
- * console.log(buf.readUIntBE(1, 6).toString(16));
1218
- * // Throws ERR_OUT_OF_RANGE.
1219
- * ```
1220
- * @since v0.11.15
1221
- * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
1222
- * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
1223
- */
1224
- readUIntBE(offset: number, byteLength: number): number;
1225
- /**
1226
- * @alias Buffer.readUIntBE
1227
- * @since v14.9.0, v12.19.0
1228
- */
1229
- readUintBE(offset: number, byteLength: number): number;
1230
- /**
1231
- * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as a little-endian, two's complement signed value
1232
- * supporting up to 48 bits of accuracy.
1233
- *
1234
- * ```js
1235
- * import { Buffer } from 'buffer';
1236
- *
1237
- * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1238
- *
1239
- * console.log(buf.readIntLE(0, 6).toString(16));
1240
- * // Prints: -546f87a9cbee
1241
- * ```
1242
- * @since v0.11.15
1243
- * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
1244
- * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
1245
- */
1246
- readIntLE(offset: number, byteLength: number): number;
1247
- /**
1248
- * Reads `byteLength` number of bytes from `buf` at the specified `offset`and interprets the result as a big-endian, two's complement signed value
1249
- * supporting up to 48 bits of accuracy.
1250
- *
1251
- * ```js
1252
- * import { Buffer } from 'buffer';
1253
- *
1254
- * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
1255
- *
1256
- * console.log(buf.readIntBE(0, 6).toString(16));
1257
- * // Prints: 1234567890ab
1258
- * console.log(buf.readIntBE(1, 6).toString(16));
1259
- * // Throws ERR_OUT_OF_RANGE.
1260
- * console.log(buf.readIntBE(1, 0).toString(16));
1261
- * // Throws ERR_OUT_OF_RANGE.
1262
- * ```
1263
- * @since v0.11.15
1264
- * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
1265
- * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
1266
- */
1267
- readIntBE(offset: number, byteLength: number): number;
1268
- /**
1269
- * Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
1270
- *
1271
- * This function is also available under the `readUint8` alias.
1272
- *
1273
- * ```js
1274
- * import { Buffer } from 'buffer';
1275
- *
1276
- * const buf = Buffer.from([1, -2]);
1277
- *
1278
- * console.log(buf.readUInt8(0));
1279
- * // Prints: 1
1280
- * console.log(buf.readUInt8(1));
1281
- * // Prints: 254
1282
- * console.log(buf.readUInt8(2));
1283
- * // Throws ERR_OUT_OF_RANGE.
1284
- * ```
1285
- * @since v0.5.0
1286
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
1287
- */
1288
- readUInt8(offset?: number): number;
1289
- /**
1290
- * @alias Buffer.readUInt8
1291
- * @since v14.9.0, v12.19.0
1292
- */
1293
- readUint8(offset?: number): number;
1294
- /**
1295
- * Reads an unsigned, little-endian 16-bit integer from `buf` at the specified`offset`.
1296
- *
1297
- * This function is also available under the `readUint16LE` alias.
1298
- *
1299
- * ```js
1300
- * import { Buffer } from 'buffer';
1301
- *
1302
- * const buf = Buffer.from([0x12, 0x34, 0x56]);
1303
- *
1304
- * console.log(buf.readUInt16LE(0).toString(16));
1305
- * // Prints: 3412
1306
- * console.log(buf.readUInt16LE(1).toString(16));
1307
- * // Prints: 5634
1308
- * console.log(buf.readUInt16LE(2).toString(16));
1309
- * // Throws ERR_OUT_OF_RANGE.
1310
- * ```
1311
- * @since v0.5.5
1312
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
1313
- */
1314
- readUInt16LE(offset?: number): number;
1315
- /**
1316
- * @alias Buffer.readUInt16LE
1317
- * @since v14.9.0, v12.19.0
1318
- */
1319
- readUint16LE(offset?: number): number;
1320
- /**
1321
- * Reads an unsigned, big-endian 16-bit integer from `buf` at the specified`offset`.
1322
- *
1323
- * This function is also available under the `readUint16BE` alias.
1324
- *
1325
- * ```js
1326
- * import { Buffer } from 'buffer';
1327
- *
1328
- * const buf = Buffer.from([0x12, 0x34, 0x56]);
1329
- *
1330
- * console.log(buf.readUInt16BE(0).toString(16));
1331
- * // Prints: 1234
1332
- * console.log(buf.readUInt16BE(1).toString(16));
1333
- * // Prints: 3456
1334
- * ```
1335
- * @since v0.5.5
1336
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
1337
- */
1338
- readUInt16BE(offset?: number): number;
1339
- /**
1340
- * @alias Buffer.readUInt16BE
1341
- * @since v14.9.0, v12.19.0
1342
- */
1343
- readUint16BE(offset?: number): number;
1344
- /**
1345
- * Reads an unsigned, little-endian 32-bit integer from `buf` at the specified`offset`.
1346
- *
1347
- * This function is also available under the `readUint32LE` alias.
1348
- *
1349
- * ```js
1350
- * import { Buffer } from 'buffer';
1351
- *
1352
- * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
1353
- *
1354
- * console.log(buf.readUInt32LE(0).toString(16));
1355
- * // Prints: 78563412
1356
- * console.log(buf.readUInt32LE(1).toString(16));
1357
- * // Throws ERR_OUT_OF_RANGE.
1358
- * ```
1359
- * @since v0.5.5
1360
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
1361
- */
1362
- readUInt32LE(offset?: number): number;
1363
- /**
1364
- * @alias Buffer.readUInt32LE
1365
- * @since v14.9.0, v12.19.0
1366
- */
1367
- readUint32LE(offset?: number): number;
1368
- /**
1369
- * Reads an unsigned, big-endian 32-bit integer from `buf` at the specified`offset`.
1370
- *
1371
- * This function is also available under the `readUint32BE` alias.
1372
- *
1373
- * ```js
1374
- * import { Buffer } from 'buffer';
1375
- *
1376
- * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
1377
- *
1378
- * console.log(buf.readUInt32BE(0).toString(16));
1379
- * // Prints: 12345678
1380
- * ```
1381
- * @since v0.5.5
1382
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
1383
- */
1384
- readUInt32BE(offset?: number): number;
1385
- /**
1386
- * @alias Buffer.readUInt32BE
1387
- * @since v14.9.0, v12.19.0
1388
- */
1389
- readUint32BE(offset?: number): number;
1390
- /**
1391
- * Reads a signed 8-bit integer from `buf` at the specified `offset`.
1392
- *
1393
- * Integers read from a `Buffer` are interpreted as two's complement signed values.
1394
- *
1395
- * ```js
1396
- * import { Buffer } from 'buffer';
1397
- *
1398
- * const buf = Buffer.from([-1, 5]);
1399
- *
1400
- * console.log(buf.readInt8(0));
1401
- * // Prints: -1
1402
- * console.log(buf.readInt8(1));
1403
- * // Prints: 5
1404
- * console.log(buf.readInt8(2));
1405
- * // Throws ERR_OUT_OF_RANGE.
1406
- * ```
1407
- * @since v0.5.0
1408
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
1409
- */
1410
- readInt8(offset?: number): number;
1411
- /**
1412
- * Reads a signed, little-endian 16-bit integer from `buf` at the specified`offset`.
1413
- *
1414
- * Integers read from a `Buffer` are interpreted as two's complement signed values.
1415
- *
1416
- * ```js
1417
- * import { Buffer } from 'buffer';
1418
- *
1419
- * const buf = Buffer.from([0, 5]);
1420
- *
1421
- * console.log(buf.readInt16LE(0));
1422
- * // Prints: 1280
1423
- * console.log(buf.readInt16LE(1));
1424
- * // Throws ERR_OUT_OF_RANGE.
1425
- * ```
1426
- * @since v0.5.5
1427
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
1428
- */
1429
- readInt16LE(offset?: number): number;
1430
- /**
1431
- * Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`.
1432
- *
1433
- * Integers read from a `Buffer` are interpreted as two's complement signed values.
1434
- *
1435
- * ```js
1436
- * import { Buffer } from 'buffer';
1437
- *
1438
- * const buf = Buffer.from([0, 5]);
1439
- *
1440
- * console.log(buf.readInt16BE(0));
1441
- * // Prints: 5
1442
- * ```
1443
- * @since v0.5.5
1444
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
1445
- */
1446
- readInt16BE(offset?: number): number;
1447
- /**
1448
- * Reads a signed, little-endian 32-bit integer from `buf` at the specified`offset`.
1449
- *
1450
- * Integers read from a `Buffer` are interpreted as two's complement signed values.
1451
- *
1452
- * ```js
1453
- * import { Buffer } from 'buffer';
1454
- *
1455
- * const buf = Buffer.from([0, 0, 0, 5]);
1456
- *
1457
- * console.log(buf.readInt32LE(0));
1458
- * // Prints: 83886080
1459
- * console.log(buf.readInt32LE(1));
1460
- * // Throws ERR_OUT_OF_RANGE.
1461
- * ```
1462
- * @since v0.5.5
1463
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
1464
- */
1465
- readInt32LE(offset?: number): number;
1466
- /**
1467
- * Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`.
1468
- *
1469
- * Integers read from a `Buffer` are interpreted as two's complement signed values.
1470
- *
1471
- * ```js
1472
- * import { Buffer } from 'buffer';
1473
- *
1474
- * const buf = Buffer.from([0, 0, 0, 5]);
1475
- *
1476
- * console.log(buf.readInt32BE(0));
1477
- * // Prints: 5
1478
- * ```
1479
- * @since v0.5.5
1480
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
1481
- */
1482
- readInt32BE(offset?: number): number;
1483
- /**
1484
- * Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
1485
- *
1486
- * ```js
1487
- * import { Buffer } from 'buffer';
1488
- *
1489
- * const buf = Buffer.from([1, 2, 3, 4]);
1490
- *
1491
- * console.log(buf.readFloatLE(0));
1492
- * // Prints: 1.539989614439558e-36
1493
- * console.log(buf.readFloatLE(1));
1494
- * // Throws ERR_OUT_OF_RANGE.
1495
- * ```
1496
- * @since v0.11.15
1497
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
1498
- */
1499
- readFloatLE(offset?: number): number;
1500
- /**
1501
- * Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
1502
- *
1503
- * ```js
1504
- * import { Buffer } from 'buffer';
1505
- *
1506
- * const buf = Buffer.from([1, 2, 3, 4]);
1507
- *
1508
- * console.log(buf.readFloatBE(0));
1509
- * // Prints: 2.387939260590663e-38
1510
- * ```
1511
- * @since v0.11.15
1512
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
1513
- */
1514
- readFloatBE(offset?: number): number;
1515
- /**
1516
- * Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
1517
- *
1518
- * ```js
1519
- * import { Buffer } from 'buffer';
1520
- *
1521
- * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
1522
- *
1523
- * console.log(buf.readDoubleLE(0));
1524
- * // Prints: 5.447603722011605e-270
1525
- * console.log(buf.readDoubleLE(1));
1526
- * // Throws ERR_OUT_OF_RANGE.
1527
- * ```
1528
- * @since v0.11.15
1529
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
1530
- */
1531
- readDoubleLE(offset?: number): number;
1532
- /**
1533
- * Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
1534
- *
1535
- * ```js
1536
- * import { Buffer } from 'buffer';
1537
- *
1538
- * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
1539
- *
1540
- * console.log(buf.readDoubleBE(0));
1541
- * // Prints: 8.20788039913184e-304
1542
- * ```
1543
- * @since v0.11.15
1544
- * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
1545
- */
1546
- readDoubleBE(offset?: number): number;
1547
- reverse(): this;
1548
- /**
1549
- * Interprets `buf` as an array of unsigned 16-bit integers and swaps the
1550
- * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 2.
1551
- *
1552
- * ```js
1553
- * import { Buffer } from 'buffer';
1554
- *
1555
- * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
1556
- *
1557
- * console.log(buf1);
1558
- * // Prints: <Buffer 01 02 03 04 05 06 07 08>
1559
- *
1560
- * buf1.swap16();
1561
- *
1562
- * console.log(buf1);
1563
- * // Prints: <Buffer 02 01 04 03 06 05 08 07>
1564
- *
1565
- * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
1566
- *
1567
- * buf2.swap16();
1568
- * // Throws ERR_INVALID_BUFFER_SIZE.
1569
- * ```
1570
- *
1571
- * One convenient use of `buf.swap16()` is to perform a fast in-place conversion
1572
- * between UTF-16 little-endian and UTF-16 big-endian:
1573
- *
1574
- * ```js
1575
- * import { Buffer } from 'buffer';
1576
- *
1577
- * const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
1578
- * buf.swap16(); // Convert to big-endian UTF-16 text.
1579
- * ```
1580
- * @since v5.10.0
1581
- * @return A reference to `buf`.
1582
- */
1583
- swap16(): Buffer;
1584
- /**
1585
- * Interprets `buf` as an array of unsigned 32-bit integers and swaps the
1586
- * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4.
1587
- *
1588
- * ```js
1589
- * import { Buffer } from 'buffer';
1590
- *
1591
- * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
1592
- *
1593
- * console.log(buf1);
1594
- * // Prints: <Buffer 01 02 03 04 05 06 07 08>
1595
- *
1596
- * buf1.swap32();
1597
- *
1598
- * console.log(buf1);
1599
- * // Prints: <Buffer 04 03 02 01 08 07 06 05>
1600
- *
1601
- * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
1602
- *
1603
- * buf2.swap32();
1604
- * // Throws ERR_INVALID_BUFFER_SIZE.
1605
- * ```
1606
- * @since v5.10.0
1607
- * @return A reference to `buf`.
1608
- */
1609
- swap32(): Buffer;
1610
- /**
1611
- * Interprets `buf` as an array of 64-bit numbers and swaps byte order _in-place_.
1612
- * Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 8.
1613
- *
1614
- * ```js
1615
- * import { Buffer } from 'buffer';
1616
- *
1617
- * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
1618
- *
1619
- * console.log(buf1);
1620
- * // Prints: <Buffer 01 02 03 04 05 06 07 08>
1621
- *
1622
- * buf1.swap64();
1623
- *
1624
- * console.log(buf1);
1625
- * // Prints: <Buffer 08 07 06 05 04 03 02 01>
1626
- *
1627
- * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
1628
- *
1629
- * buf2.swap64();
1630
- * // Throws ERR_INVALID_BUFFER_SIZE.
1631
- * ```
1632
- * @since v6.3.0
1633
- * @return A reference to `buf`.
1634
- */
1635
- swap64(): Buffer;
1636
- /**
1637
- * Writes `value` to `buf` at the specified `offset`. `value` must be a
1638
- * valid unsigned 8-bit integer. Behavior is undefined when `value` is anything
1639
- * other than an unsigned 8-bit integer.
1640
- *
1641
- * This function is also available under the `writeUint8` alias.
1642
- *
1643
- * ```js
1644
- * import { Buffer } from 'buffer';
1645
- *
1646
- * const buf = Buffer.allocUnsafe(4);
1647
- *
1648
- * buf.writeUInt8(0x3, 0);
1649
- * buf.writeUInt8(0x4, 1);
1650
- * buf.writeUInt8(0x23, 2);
1651
- * buf.writeUInt8(0x42, 3);
1652
- *
1653
- * console.log(buf);
1654
- * // Prints: <Buffer 03 04 23 42>
1655
- * ```
1656
- * @since v0.5.0
1657
- * @param value Number to be written to `buf`.
1658
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
1659
- * @return `offset` plus the number of bytes written.
1660
- */
1661
- writeUInt8(value: number, offset?: number): number;
1662
- /**
1663
- * @alias Buffer.writeUInt8
1664
- * @since v14.9.0, v12.19.0
1665
- */
1666
- writeUint8(value: number, offset?: number): number;
1667
- /**
1668
- * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a valid unsigned 16-bit integer. Behavior is undefined when `value` is
1669
- * anything other than an unsigned 16-bit integer.
1670
- *
1671
- * This function is also available under the `writeUint16LE` alias.
1672
- *
1673
- * ```js
1674
- * import { Buffer } from 'buffer';
1675
- *
1676
- * const buf = Buffer.allocUnsafe(4);
1677
- *
1678
- * buf.writeUInt16LE(0xdead, 0);
1679
- * buf.writeUInt16LE(0xbeef, 2);
1680
- *
1681
- * console.log(buf);
1682
- * // Prints: <Buffer ad de ef be>
1683
- * ```
1684
- * @since v0.5.5
1685
- * @param value Number to be written to `buf`.
1686
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
1687
- * @return `offset` plus the number of bytes written.
1688
- */
1689
- writeUInt16LE(value: number, offset?: number): number;
1690
- /**
1691
- * @alias Buffer.writeUInt16LE
1692
- * @since v14.9.0, v12.19.0
1693
- */
1694
- writeUint16LE(value: number, offset?: number): number;
1695
- /**
1696
- * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a valid unsigned 16-bit integer. Behavior is undefined when `value`is anything other than an
1697
- * unsigned 16-bit integer.
1698
- *
1699
- * This function is also available under the `writeUint16BE` alias.
1700
- *
1701
- * ```js
1702
- * import { Buffer } from 'buffer';
1703
- *
1704
- * const buf = Buffer.allocUnsafe(4);
1705
- *
1706
- * buf.writeUInt16BE(0xdead, 0);
1707
- * buf.writeUInt16BE(0xbeef, 2);
1708
- *
1709
- * console.log(buf);
1710
- * // Prints: <Buffer de ad be ef>
1711
- * ```
1712
- * @since v0.5.5
1713
- * @param value Number to be written to `buf`.
1714
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
1715
- * @return `offset` plus the number of bytes written.
1716
- */
1717
- writeUInt16BE(value: number, offset?: number): number;
1718
- /**
1719
- * @alias Buffer.writeUInt16BE
1720
- * @since v14.9.0, v12.19.0
1721
- */
1722
- writeUint16BE(value: number, offset?: number): number;
1723
- /**
1724
- * Writes `value` to `buf` at the specified `offset` as little-endian. The `value`must be a valid unsigned 32-bit integer. Behavior is undefined when `value` is
1725
- * anything other than an unsigned 32-bit integer.
1726
- *
1727
- * This function is also available under the `writeUint32LE` alias.
1728
- *
1729
- * ```js
1730
- * import { Buffer } from 'buffer';
1731
- *
1732
- * const buf = Buffer.allocUnsafe(4);
1733
- *
1734
- * buf.writeUInt32LE(0xfeedface, 0);
1735
- *
1736
- * console.log(buf);
1737
- * // Prints: <Buffer ce fa ed fe>
1738
- * ```
1739
- * @since v0.5.5
1740
- * @param value Number to be written to `buf`.
1741
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
1742
- * @return `offset` plus the number of bytes written.
1743
- */
1744
- writeUInt32LE(value: number, offset?: number): number;
1745
- /**
1746
- * @alias Buffer.writeUInt32LE
1747
- * @since v14.9.0, v12.19.0
1748
- */
1749
- writeUint32LE(value: number, offset?: number): number;
1750
- /**
1751
- * Writes `value` to `buf` at the specified `offset` as big-endian. The `value`must be a valid unsigned 32-bit integer. Behavior is undefined when `value`is anything other than an
1752
- * unsigned 32-bit integer.
1753
- *
1754
- * This function is also available under the `writeUint32BE` alias.
1755
- *
1756
- * ```js
1757
- * import { Buffer } from 'buffer';
1758
- *
1759
- * const buf = Buffer.allocUnsafe(4);
1760
- *
1761
- * buf.writeUInt32BE(0xfeedface, 0);
1762
- *
1763
- * console.log(buf);
1764
- * // Prints: <Buffer fe ed fa ce>
1765
- * ```
1766
- * @since v0.5.5
1767
- * @param value Number to be written to `buf`.
1768
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
1769
- * @return `offset` plus the number of bytes written.
1770
- */
1771
- writeUInt32BE(value: number, offset?: number): number;
1772
- /**
1773
- * @alias Buffer.writeUInt32BE
1774
- * @since v14.9.0, v12.19.0
1775
- */
1776
- writeUint32BE(value: number, offset?: number): number;
1777
- /**
1778
- * Writes `value` to `buf` at the specified `offset`. `value` must be a valid
1779
- * signed 8-bit integer. Behavior is undefined when `value` is anything other than
1780
- * a signed 8-bit integer.
1781
- *
1782
- * `value` is interpreted and written as a two's complement signed integer.
1783
- *
1784
- * ```js
1785
- * import { Buffer } from 'buffer';
1786
- *
1787
- * const buf = Buffer.allocUnsafe(2);
1788
- *
1789
- * buf.writeInt8(2, 0);
1790
- * buf.writeInt8(-2, 1);
1791
- *
1792
- * console.log(buf);
1793
- * // Prints: <Buffer 02 fe>
1794
- * ```
1795
- * @since v0.5.0
1796
- * @param value Number to be written to `buf`.
1797
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
1798
- * @return `offset` plus the number of bytes written.
1799
- */
1800
- writeInt8(value: number, offset?: number): number;
1801
- /**
1802
- * 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
1803
- * anything other than a signed 16-bit integer.
1804
- *
1805
- * The `value` is interpreted and written as a two's complement signed integer.
1806
- *
1807
- * ```js
1808
- * import { Buffer } from 'buffer';
1809
- *
1810
- * const buf = Buffer.allocUnsafe(2);
1811
- *
1812
- * buf.writeInt16LE(0x0304, 0);
1813
- *
1814
- * console.log(buf);
1815
- * // Prints: <Buffer 04 03>
1816
- * ```
1817
- * @since v0.5.5
1818
- * @param value Number to be written to `buf`.
1819
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
1820
- * @return `offset` plus the number of bytes written.
1821
- */
1822
- writeInt16LE(value: number, offset?: number): number;
1823
- /**
1824
- * 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
1825
- * anything other than a signed 16-bit integer.
1826
- *
1827
- * The `value` is interpreted and written as a two's complement signed integer.
1828
- *
1829
- * ```js
1830
- * import { Buffer } from 'buffer';
1831
- *
1832
- * const buf = Buffer.allocUnsafe(2);
1833
- *
1834
- * buf.writeInt16BE(0x0102, 0);
1835
- *
1836
- * console.log(buf);
1837
- * // Prints: <Buffer 01 02>
1838
- * ```
1839
- * @since v0.5.5
1840
- * @param value Number to be written to `buf`.
1841
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
1842
- * @return `offset` plus the number of bytes written.
1843
- */
1844
- writeInt16BE(value: number, offset?: number): number;
1845
- /**
1846
- * 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
1847
- * anything other than a signed 32-bit integer.
1848
- *
1849
- * The `value` is interpreted and written as a two's complement signed integer.
1850
- *
1851
- * ```js
1852
- * import { Buffer } from 'buffer';
1853
- *
1854
- * const buf = Buffer.allocUnsafe(4);
1855
- *
1856
- * buf.writeInt32LE(0x05060708, 0);
1857
- *
1858
- * console.log(buf);
1859
- * // Prints: <Buffer 08 07 06 05>
1860
- * ```
1861
- * @since v0.5.5
1862
- * @param value Number to be written to `buf`.
1863
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
1864
- * @return `offset` plus the number of bytes written.
1865
- */
1866
- writeInt32LE(value: number, offset?: number): number;
1867
- /**
1868
- * 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
1869
- * anything other than a signed 32-bit integer.
1870
- *
1871
- * The `value` is interpreted and written as a two's complement signed integer.
1872
- *
1873
- * ```js
1874
- * import { Buffer } from 'buffer';
1875
- *
1876
- * const buf = Buffer.allocUnsafe(4);
1877
- *
1878
- * buf.writeInt32BE(0x01020304, 0);
1879
- *
1880
- * console.log(buf);
1881
- * // Prints: <Buffer 01 02 03 04>
1882
- * ```
1883
- * @since v0.5.5
1884
- * @param value Number to be written to `buf`.
1885
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
1886
- * @return `offset` plus the number of bytes written.
1887
- */
1888
- writeInt32BE(value: number, offset?: number): number;
1889
- /**
1890
- * Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
1891
- * undefined when `value` is anything other than a JavaScript number.
1892
- *
1893
- * ```js
1894
- * import { Buffer } from 'buffer';
1895
- *
1896
- * const buf = Buffer.allocUnsafe(4);
1897
- *
1898
- * buf.writeFloatLE(0xcafebabe, 0);
1899
- *
1900
- * console.log(buf);
1901
- * // Prints: <Buffer bb fe 4a 4f>
1902
- * ```
1903
- * @since v0.11.15
1904
- * @param value Number to be written to `buf`.
1905
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
1906
- * @return `offset` plus the number of bytes written.
1907
- */
1908
- writeFloatLE(value: number, offset?: number): number;
1909
- /**
1910
- * Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
1911
- * undefined when `value` is anything other than a JavaScript number.
1912
- *
1913
- * ```js
1914
- * import { Buffer } from 'buffer';
1915
- *
1916
- * const buf = Buffer.allocUnsafe(4);
1917
- *
1918
- * buf.writeFloatBE(0xcafebabe, 0);
1919
- *
1920
- * console.log(buf);
1921
- * // Prints: <Buffer 4f 4a fe bb>
1922
- * ```
1923
- * @since v0.11.15
1924
- * @param value Number to be written to `buf`.
1925
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
1926
- * @return `offset` plus the number of bytes written.
1927
- */
1928
- writeFloatBE(value: number, offset?: number): number;
1929
- /**
1930
- * 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
1931
- * other than a JavaScript number.
1932
- *
1933
- * ```js
1934
- * import { Buffer } from 'buffer';
1935
- *
1936
- * const buf = Buffer.allocUnsafe(8);
1937
- *
1938
- * buf.writeDoubleLE(123.456, 0);
1939
- *
1940
- * console.log(buf);
1941
- * // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
1942
- * ```
1943
- * @since v0.11.15
1944
- * @param value Number to be written to `buf`.
1945
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
1946
- * @return `offset` plus the number of bytes written.
1947
- */
1948
- writeDoubleLE(value: number, offset?: number): number;
1949
- /**
1950
- * 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
1951
- * other than a JavaScript number.
1952
- *
1953
- * ```js
1954
- * import { Buffer } from 'buffer';
1955
- *
1956
- * const buf = Buffer.allocUnsafe(8);
1957
- *
1958
- * buf.writeDoubleBE(123.456, 0);
1959
- *
1960
- * console.log(buf);
1961
- * // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
1962
- * ```
1963
- * @since v0.11.15
1964
- * @param value Number to be written to `buf`.
1965
- * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
1966
- * @return `offset` plus the number of bytes written.
1967
- */
1968
- writeDoubleBE(value: number, offset?: number): number;
1969
- /**
1970
- * Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
1971
- * the entire `buf` will be filled:
1972
- *
1973
- * ```js
1974
- * import { Buffer } from 'buffer';
1975
- *
1976
- * // Fill a `Buffer` with the ASCII character 'h'.
1977
- *
1978
- * const b = Buffer.allocUnsafe(50).fill('h');
1979
- *
1980
- * console.log(b.toString());
1981
- * // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
1982
- * ```
1983
- *
1984
- * `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
1985
- * integer. If the resulting integer is greater than `255` (decimal), `buf` will be
1986
- * filled with `value &#x26; 255`.
1987
- *
1988
- * If the final write of a `fill()` operation falls on a multi-byte character,
1989
- * then only the bytes of that character that fit into `buf` are written:
1990
- *
1991
- * ```js
1992
- * import { Buffer } from 'buffer';
1993
- *
1994
- * // Fill a `Buffer` with character that takes up two bytes in UTF-8.
1995
- *
1996
- * console.log(Buffer.allocUnsafe(5).fill('\u0222'));
1997
- * // Prints: <Buffer c8 a2 c8 a2 c8>
1998
- * ```
1999
- *
2000
- * If `value` contains invalid characters, it is truncated; if no valid
2001
- * fill data remains, an exception is thrown:
2002
- *
2003
- * ```js
2004
- * import { Buffer } from 'buffer';
2005
- *
2006
- * const buf = Buffer.allocUnsafe(5);
2007
- *
2008
- * console.log(buf.fill('a'));
2009
- * // Prints: <Buffer 61 61 61 61 61>
2010
- * console.log(buf.fill('aazz', 'hex'));
2011
- * // Prints: <Buffer aa aa aa aa aa>
2012
- * console.log(buf.fill('zz', 'hex'));
2013
- * // Throws an exception.
2014
- * ```
2015
- * @since v0.5.0
2016
- * @param value The value with which to fill `buf`.
2017
- * @param [offset=0] Number of bytes to skip before starting to fill `buf`.
2018
- * @param [end=buf.length] Where to stop filling `buf` (not inclusive).
2019
- * @param [encoding='utf8'] The encoding for `value` if `value` is a string.
2020
- * @return A reference to `buf`.
2021
- */
2022
- fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
2023
- /**
2024
- * If `value` is:
2025
- *
2026
- * * a string, `value` is interpreted according to the character encoding in`encoding`.
2027
- * * a `Buffer` or [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), `value` will be used in its entirety.
2028
- * To compare a partial `Buffer`, use `buf.subarray`.
2029
- * * a number, `value` will be interpreted as an unsigned 8-bit integer
2030
- * value between `0` and `255`.
2031
- *
2032
- * ```js
2033
- * import { Buffer } from 'buffer';
2034
- *
2035
- * const buf = Buffer.from('this is a buffer');
2036
- *
2037
- * console.log(buf.indexOf('this'));
2038
- * // Prints: 0
2039
- * console.log(buf.indexOf('is'));
2040
- * // Prints: 2
2041
- * console.log(buf.indexOf(Buffer.from('a buffer')));
2042
- * // Prints: 8
2043
- * console.log(buf.indexOf(97));
2044
- * // Prints: 8 (97 is the decimal ASCII value for 'a')
2045
- * console.log(buf.indexOf(Buffer.from('a buffer example')));
2046
- * // Prints: -1
2047
- * console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
2048
- * // Prints: 8
2049
- *
2050
- * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
2051
- *
2052
- * console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
2053
- * // Prints: 4
2054
- * console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
2055
- * // Prints: 6
2056
- * ```
2057
- *
2058
- * If `value` is not a string, number, or `Buffer`, this method will throw a`TypeError`. If `value` is a number, it will be coerced to a valid byte value,
2059
- * an integer between 0 and 255.
2060
- *
2061
- * If `byteOffset` is not a number, it will be coerced to a number. If the result
2062
- * of coercion is `NaN` or `0`, then the entire buffer will be searched. This
2063
- * behavior matches [`String.prototype.indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf).
2064
- *
2065
- * ```js
2066
- * import { Buffer } from 'buffer';
2067
- *
2068
- * const b = Buffer.from('abcdef');
2069
- *
2070
- * // Passing a value that's a number, but not a valid byte.
2071
- * // Prints: 2, equivalent to searching for 99 or 'c'.
2072
- * console.log(b.indexOf(99.9));
2073
- * console.log(b.indexOf(256 + 99));
2074
- *
2075
- * // Passing a byteOffset that coerces to NaN or 0.
2076
- * // Prints: 1, searching the whole buffer.
2077
- * console.log(b.indexOf('b', undefined));
2078
- * console.log(b.indexOf('b', {}));
2079
- * console.log(b.indexOf('b', null));
2080
- * console.log(b.indexOf('b', []));
2081
- * ```
2082
- *
2083
- * If `value` is an empty string or empty `Buffer` and `byteOffset` is less
2084
- * than `buf.length`, `byteOffset` will be returned. If `value` is empty and`byteOffset` is at least `buf.length`, `buf.length` will be returned.
2085
- * @since v1.5.0
2086
- * @param value What to search for.
2087
- * @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
2088
- * @param [encoding='utf8'] If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.
2089
- * @return The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
2090
- */
2091
- indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
2092
- /**
2093
- * Identical to `buf.indexOf()`, except the last occurrence of `value` is found
2094
- * rather than the first occurrence.
2095
- *
2096
- * ```js
2097
- * import { Buffer } from 'buffer';
2098
- *
2099
- * const buf = Buffer.from('this buffer is a buffer');
2100
- *
2101
- * console.log(buf.lastIndexOf('this'));
2102
- * // Prints: 0
2103
- * console.log(buf.lastIndexOf('buffer'));
2104
- * // Prints: 17
2105
- * console.log(buf.lastIndexOf(Buffer.from('buffer')));
2106
- * // Prints: 17
2107
- * console.log(buf.lastIndexOf(97));
2108
- * // Prints: 15 (97 is the decimal ASCII value for 'a')
2109
- * console.log(buf.lastIndexOf(Buffer.from('yolo')));
2110
- * // Prints: -1
2111
- * console.log(buf.lastIndexOf('buffer', 5));
2112
- * // Prints: 5
2113
- * console.log(buf.lastIndexOf('buffer', 4));
2114
- * // Prints: -1
2115
- *
2116
- * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
2117
- *
2118
- * console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
2119
- * // Prints: 6
2120
- * console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
2121
- * // Prints: 4
2122
- * ```
2123
- *
2124
- * If `value` is not a string, number, or `Buffer`, this method will throw a`TypeError`. If `value` is a number, it will be coerced to a valid byte value,
2125
- * an integer between 0 and 255.
2126
- *
2127
- * If `byteOffset` is not a number, it will be coerced to a number. Any arguments
2128
- * that coerce to `NaN`, like `{}` or `undefined`, will search the whole buffer.
2129
- * This behavior matches [`String.prototype.lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf).
2130
- *
2131
- * ```js
2132
- * import { Buffer } from 'buffer';
2133
- *
2134
- * const b = Buffer.from('abcdef');
2135
- *
2136
- * // Passing a value that's a number, but not a valid byte.
2137
- * // Prints: 2, equivalent to searching for 99 or 'c'.
2138
- * console.log(b.lastIndexOf(99.9));
2139
- * console.log(b.lastIndexOf(256 + 99));
2140
- *
2141
- * // Passing a byteOffset that coerces to NaN.
2142
- * // Prints: 1, searching the whole buffer.
2143
- * console.log(b.lastIndexOf('b', undefined));
2144
- * console.log(b.lastIndexOf('b', {}));
2145
- *
2146
- * // Passing a byteOffset that coerces to 0.
2147
- * // Prints: -1, equivalent to passing 0.
2148
- * console.log(b.lastIndexOf('b', null));
2149
- * console.log(b.lastIndexOf('b', []));
2150
- * ```
2151
- *
2152
- * If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned.
2153
- * @since v6.0.0
2154
- * @param value What to search for.
2155
- * @param [byteOffset=buf.length - 1] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
2156
- * @param [encoding='utf8'] If `value` is a string, this is the encoding used to determine the binary representation of the string that will be searched for in `buf`.
2157
- * @return The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
2158
- */
2159
- lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
2160
- /**
2161
- * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) of `[index, byte]` pairs from the contents
2162
- * of `buf`.
2163
- *
2164
- * ```js
2165
- * import { Buffer } from 'buffer';
2166
- *
2167
- * // Log the entire contents of a `Buffer`.
2168
- *
2169
- * const buf = Buffer.from('buffer');
2170
- *
2171
- * for (const pair of buf.entries()) {
2172
- * console.log(pair);
2173
- * }
2174
- * // Prints:
2175
- * // [0, 98]
2176
- * // [1, 117]
2177
- * // [2, 102]
2178
- * // [3, 102]
2179
- * // [4, 101]
2180
- * // [5, 114]
2181
- * ```
2182
- * @since v1.1.0
2183
- */
2184
- entries(): IterableIterator<[number, number]>;
2185
- /**
2186
- * Equivalent to `buf.indexOf() !== -1`.
2187
- *
2188
- * ```js
2189
- * import { Buffer } from 'buffer';
2190
- *
2191
- * const buf = Buffer.from('this is a buffer');
2192
- *
2193
- * console.log(buf.includes('this'));
2194
- * // Prints: true
2195
- * console.log(buf.includes('is'));
2196
- * // Prints: true
2197
- * console.log(buf.includes(Buffer.from('a buffer')));
2198
- * // Prints: true
2199
- * console.log(buf.includes(97));
2200
- * // Prints: true (97 is the decimal ASCII value for 'a')
2201
- * console.log(buf.includes(Buffer.from('a buffer example')));
2202
- * // Prints: false
2203
- * console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
2204
- * // Prints: true
2205
- * console.log(buf.includes('this', 4));
2206
- * // Prints: false
2207
- * ```
2208
- * @since v5.3.0
2209
- * @param value What to search for.
2210
- * @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
2211
- * @param [encoding='utf8'] If `value` is a string, this is its encoding.
2212
- * @return `true` if `value` was found in `buf`, `false` otherwise.
2213
- */
2214
- includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
2215
- /**
2216
- * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) of `buf` keys (indices).
2217
- *
2218
- * ```js
2219
- * import { Buffer } from 'buffer';
2220
- *
2221
- * const buf = Buffer.from('buffer');
2222
- *
2223
- * for (const key of buf.keys()) {
2224
- * console.log(key);
2225
- * }
2226
- * // Prints:
2227
- * // 0
2228
- * // 1
2229
- * // 2
2230
- * // 3
2231
- * // 4
2232
- * // 5
2233
- * ```
2234
- * @since v1.1.0
2235
- */
2236
- keys(): IterableIterator<number>;
2237
- /**
2238
- * Creates and returns an [iterator](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Iteration_protocols) for `buf` values (bytes). This function is
2239
- * called automatically when a `Buffer` is used in a `for..of` statement.
2240
- *
2241
- * ```js
2242
- * import { Buffer } from 'buffer';
2243
- *
2244
- * const buf = Buffer.from('buffer');
2245
- *
2246
- * for (const value of buf.values()) {
2247
- * console.log(value);
2248
- * }
2249
- * // Prints:
2250
- * // 98
2251
- * // 117
2252
- * // 102
2253
- * // 102
2254
- * // 101
2255
- * // 114
2256
- *
2257
- * for (const value of buf) {
2258
- * console.log(value);
2259
- * }
2260
- * // Prints:
2261
- * // 98
2262
- * // 117
2263
- * // 102
2264
- * // 102
2265
- * // 101
2266
- * // 114
2267
- * ```
2268
- * @since v1.1.0
2269
- */
2270
- values(): IterableIterator<number>;
2271
- }
2272
- var Buffer: BufferConstructor;
2273
- /**
2274
- * Decodes a string of Base64-encoded data into bytes, and encodes those bytes
2275
- * into a string using Latin-1 (ISO-8859-1).
2276
- *
2277
- * The `data` may be any JavaScript-value that can be coerced into a string.
2278
- *
2279
- * **This function is only provided for compatibility with legacy web platform APIs**
2280
- * **and should never be used in new code, because they use strings to represent**
2281
- * **binary data and predate the introduction of typed arrays in JavaScript.**
2282
- * **For code running using Node.js APIs, converting between base64-encoded strings**
2283
- * **and binary data should be performed using `Buffer.from(str, 'base64')` and`buf.toString('base64')`.**
2284
- * @since v15.13.0, v14.17.0
2285
- * @legacy Use `Buffer.from(data, 'base64')` instead.
2286
- * @param data The Base64-encoded input string.
2287
- */
2288
- function atob(data: string): string;
2289
- /**
2290
- * Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes
2291
- * into a string using Base64.
2292
- *
2293
- * The `data` may be any JavaScript-value that can be coerced into a string.
2294
- *
2295
- * **This function is only provided for compatibility with legacy web platform APIs**
2296
- * **and should never be used in new code, because they use strings to represent**
2297
- * **binary data and predate the introduction of typed arrays in JavaScript.**
2298
- * **For code running using Node.js APIs, converting between base64-encoded strings**
2299
- * **and binary data should be performed using `Buffer.from(str, 'base64')` and`buf.toString('base64')`.**
2300
- * @since v15.13.0, v14.17.0
2301
- * @legacy Use `buf.toString('base64')` instead.
2302
- * @param data An ASCII (Latin1) string.
2303
- */
2304
- function btoa(data: string): string;
2305
-
2306
- interface Blob extends __Blob {}
2307
- /**
2308
- * `Blob` class is a global reference for `require('node:buffer').Blob`
2309
- * https://nodejs.org/api/buffer.html#class-blob
2310
- * @since v18.0.0
2311
- */
2312
- var Blob: typeof globalThis extends {
2313
- onmessage: any;
2314
- Blob: infer T;
2315
- } ? T
2316
- : typeof NodeBlob;
2317
- }
2318
- }
2319
- declare module "node:buffer" {
2320
- export * from "buffer";
2321
- }