ff65b56c6ec0c75cf79b97ce22c875b0af04e337928e32471c21595805b981d8e019ea60502c130442582bfaa9356a1841a019db21936edaa5ff34ffbb1a08 86 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926
  1. // If lib.dom.d.ts or lib.webworker.d.ts is loaded, then use the global types.
  2. // Otherwise, use the types from node.
  3. type _Blob = typeof globalThis extends { onmessage: any; Blob: any } ? {} : import("buffer").Blob;
  4. type _File = typeof globalThis extends { onmessage: any; File: any } ? {} : import("buffer").File;
  5. /**
  6. * `Buffer` objects are used to represent a fixed-length sequence of bytes. Many
  7. * Node.js APIs support `Buffer`s.
  8. *
  9. * 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
  10. * extends it with methods that cover additional use cases. Node.js APIs accept
  11. * plain [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array) s wherever `Buffer`s are supported as well.
  12. *
  13. * While the `Buffer` class is available within the global scope, it is still
  14. * recommended to explicitly reference it via an import or require statement.
  15. *
  16. * ```js
  17. * import { Buffer } from 'node:buffer';
  18. *
  19. * // Creates a zero-filled Buffer of length 10.
  20. * const buf1 = Buffer.alloc(10);
  21. *
  22. * // Creates a Buffer of length 10,
  23. * // filled with bytes which all have the value `1`.
  24. * const buf2 = Buffer.alloc(10, 1);
  25. *
  26. * // Creates an uninitialized buffer of length 10.
  27. * // This is faster than calling Buffer.alloc() but the returned
  28. * // Buffer instance might contain old data that needs to be
  29. * // overwritten using fill(), write(), or other functions that fill the Buffer's
  30. * // contents.
  31. * const buf3 = Buffer.allocUnsafe(10);
  32. *
  33. * // Creates a Buffer containing the bytes [1, 2, 3].
  34. * const buf4 = Buffer.from([1, 2, 3]);
  35. *
  36. * // Creates a Buffer containing the bytes [1, 1, 1, 1] – the entries
  37. * // are all truncated using `(value & 255)` to fit into the range 0–255.
  38. * const buf5 = Buffer.from([257, 257.5, -255, '1']);
  39. *
  40. * // Creates a Buffer containing the UTF-8-encoded bytes for the string 'tést':
  41. * // [0x74, 0xc3, 0xa9, 0x73, 0x74] (in hexadecimal notation)
  42. * // [116, 195, 169, 115, 116] (in decimal notation)
  43. * const buf6 = Buffer.from('tést');
  44. *
  45. * // Creates a Buffer containing the Latin-1 bytes [0x74, 0xe9, 0x73, 0x74].
  46. * const buf7 = Buffer.from('tést', 'latin1');
  47. * ```
  48. * @see [source](https://github.com/nodejs/node/blob/v22.x/lib/buffer.js)
  49. */
  50. declare module "buffer" {
  51. import { BinaryLike } from "node:crypto";
  52. import { ReadableStream as WebReadableStream } from "node:stream/web";
  53. /**
  54. * This function returns `true` if `input` contains only valid UTF-8-encoded data,
  55. * including the case in which `input` is empty.
  56. *
  57. * Throws if the `input` is a detached array buffer.
  58. * @since v19.4.0, v18.14.0
  59. * @param input The input to validate.
  60. */
  61. export function isUtf8(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
  62. /**
  63. * This function returns `true` if `input` contains only valid ASCII-encoded data,
  64. * including the case in which `input` is empty.
  65. *
  66. * Throws if the `input` is a detached array buffer.
  67. * @since v19.6.0, v18.15.0
  68. * @param input The input to validate.
  69. */
  70. export function isAscii(input: Buffer | ArrayBuffer | NodeJS.TypedArray): boolean;
  71. export let INSPECT_MAX_BYTES: number;
  72. export const kMaxLength: number;
  73. export const kStringMaxLength: number;
  74. export const constants: {
  75. MAX_LENGTH: number;
  76. MAX_STRING_LENGTH: number;
  77. };
  78. export type TranscodeEncoding =
  79. | "ascii"
  80. | "utf8"
  81. | "utf-8"
  82. | "utf16le"
  83. | "utf-16le"
  84. | "ucs2"
  85. | "ucs-2"
  86. | "latin1"
  87. | "binary";
  88. /**
  89. * Re-encodes the given `Buffer` or `Uint8Array` instance from one character
  90. * encoding to another. Returns a new `Buffer` instance.
  91. *
  92. * Throws if the `fromEnc` or `toEnc` specify invalid character encodings or if
  93. * conversion from `fromEnc` to `toEnc` is not permitted.
  94. *
  95. * Encodings supported by `buffer.transcode()` are: `'ascii'`, `'utf8'`, `'utf16le'`, `'ucs2'`, `'latin1'`, and `'binary'`.
  96. *
  97. * The transcoding process will use substitution characters if a given byte
  98. * sequence cannot be adequately represented in the target encoding. For instance:
  99. *
  100. * ```js
  101. * import { Buffer, transcode } from 'node:buffer';
  102. *
  103. * const newBuf = transcode(Buffer.from('€'), 'utf8', 'ascii');
  104. * console.log(newBuf.toString('ascii'));
  105. * // Prints: '?'
  106. * ```
  107. *
  108. * Because the Euro (`€`) sign is not representable in US-ASCII, it is replaced
  109. * with `?` in the transcoded `Buffer`.
  110. * @since v7.1.0
  111. * @param source A `Buffer` or `Uint8Array` instance.
  112. * @param fromEnc The current encoding.
  113. * @param toEnc To target encoding.
  114. */
  115. export function transcode(source: Uint8Array, fromEnc: TranscodeEncoding, toEnc: TranscodeEncoding): Buffer;
  116. /**
  117. * Resolves a `'blob:nodedata:...'` an associated `Blob` object registered using
  118. * a prior call to `URL.createObjectURL()`.
  119. * @since v16.7.0
  120. * @experimental
  121. * @param id A `'blob:nodedata:...` URL string returned by a prior call to `URL.createObjectURL()`.
  122. */
  123. export function resolveObjectURL(id: string): Blob | undefined;
  124. export { type AllowSharedBuffer, Buffer, type NonSharedBuffer };
  125. /**
  126. * @experimental
  127. */
  128. export interface BlobOptions {
  129. /**
  130. * One of either `'transparent'` or `'native'`. When set to `'native'`, line endings in string source parts
  131. * will be converted to the platform native line-ending as specified by `import { EOL } from 'node:os'`.
  132. */
  133. endings?: "transparent" | "native";
  134. /**
  135. * The Blob content-type. The intent is for `type` to convey
  136. * the MIME media type of the data, however no validation of the type format
  137. * is performed.
  138. */
  139. type?: string | undefined;
  140. }
  141. /**
  142. * A [`Blob`](https://developer.mozilla.org/en-US/docs/Web/API/Blob) encapsulates immutable, raw data that can be safely shared across
  143. * multiple worker threads.
  144. * @since v15.7.0, v14.18.0
  145. */
  146. export class Blob {
  147. /**
  148. * The total size of the `Blob` in bytes.
  149. * @since v15.7.0, v14.18.0
  150. */
  151. readonly size: number;
  152. /**
  153. * The content-type of the `Blob`.
  154. * @since v15.7.0, v14.18.0
  155. */
  156. readonly type: string;
  157. /**
  158. * Creates a new `Blob` object containing a concatenation of the given sources.
  159. *
  160. * {ArrayBuffer}, {TypedArray}, {DataView}, and {Buffer} sources are copied into
  161. * the 'Blob' and can therefore be safely modified after the 'Blob' is created.
  162. *
  163. * String sources are also copied into the `Blob`.
  164. */
  165. constructor(sources: Array<ArrayBuffer | BinaryLike | Blob>, options?: BlobOptions);
  166. /**
  167. * 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
  168. * the `Blob` data.
  169. * @since v15.7.0, v14.18.0
  170. */
  171. arrayBuffer(): Promise<ArrayBuffer>;
  172. /**
  173. * The `blob.bytes()` method returns the byte of the `Blob` object as a `Promise<Uint8Array>`.
  174. *
  175. * ```js
  176. * const blob = new Blob(['hello']);
  177. * blob.bytes().then((bytes) => {
  178. * console.log(bytes); // Outputs: Uint8Array(5) [ 104, 101, 108, 108, 111 ]
  179. * });
  180. * ```
  181. */
  182. bytes(): Promise<Uint8Array>;
  183. /**
  184. * Creates and returns a new `Blob` containing a subset of this `Blob` objects
  185. * data. The original `Blob` is not altered.
  186. * @since v15.7.0, v14.18.0
  187. * @param start The starting index.
  188. * @param end The ending index.
  189. * @param type The content-type for the new `Blob`
  190. */
  191. slice(start?: number, end?: number, type?: string): Blob;
  192. /**
  193. * Returns a promise that fulfills with the contents of the `Blob` decoded as a
  194. * UTF-8 string.
  195. * @since v15.7.0, v14.18.0
  196. */
  197. text(): Promise<string>;
  198. /**
  199. * Returns a new `ReadableStream` that allows the content of the `Blob` to be read.
  200. * @since v16.7.0
  201. */
  202. stream(): WebReadableStream;
  203. }
  204. export interface FileOptions {
  205. /**
  206. * One of either `'transparent'` or `'native'`. When set to `'native'`, line endings in string source parts will be
  207. * converted to the platform native line-ending as specified by `import { EOL } from 'node:os'`.
  208. */
  209. endings?: "native" | "transparent";
  210. /** The File content-type. */
  211. type?: string;
  212. /** The last modified date of the file. `Default`: Date.now(). */
  213. lastModified?: number;
  214. }
  215. /**
  216. * A [`File`](https://developer.mozilla.org/en-US/docs/Web/API/File) provides information about files.
  217. * @since v19.2.0, v18.13.0
  218. */
  219. export class File extends Blob {
  220. constructor(sources: Array<BinaryLike | Blob>, fileName: string, options?: FileOptions);
  221. /**
  222. * The name of the `File`.
  223. * @since v19.2.0, v18.13.0
  224. */
  225. readonly name: string;
  226. /**
  227. * The last modified date of the `File`.
  228. * @since v19.2.0, v18.13.0
  229. */
  230. readonly lastModified: number;
  231. }
  232. export import atob = globalThis.atob;
  233. export import btoa = globalThis.btoa;
  234. export type WithImplicitCoercion<T> =
  235. | T
  236. | { valueOf(): T }
  237. | (T extends string ? { [Symbol.toPrimitive](hint: "string"): T } : never);
  238. global {
  239. namespace NodeJS {
  240. export { BufferEncoding };
  241. }
  242. // Buffer class
  243. type BufferEncoding =
  244. | "ascii"
  245. | "utf8"
  246. | "utf-8"
  247. | "utf16le"
  248. | "utf-16le"
  249. | "ucs2"
  250. | "ucs-2"
  251. | "base64"
  252. | "base64url"
  253. | "latin1"
  254. | "binary"
  255. | "hex";
  256. /**
  257. * Raw data is stored in instances of the Buffer class.
  258. * 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.
  259. * Valid string encodings: 'ascii'|'utf8'|'utf16le'|'ucs2'(alias of 'utf16le')|'base64'|'base64url'|'binary'(deprecated)|'hex'
  260. */
  261. interface BufferConstructor {
  262. // see buffer.buffer.d.ts for implementation specific to TypeScript 5.7 and later
  263. // see ts5.6/buffer.buffer.d.ts for implementation specific to TypeScript 5.6 and earlier
  264. /**
  265. * Returns `true` if `obj` is a `Buffer`, `false` otherwise.
  266. *
  267. * ```js
  268. * import { Buffer } from 'node:buffer';
  269. *
  270. * Buffer.isBuffer(Buffer.alloc(10)); // true
  271. * Buffer.isBuffer(Buffer.from('foo')); // true
  272. * Buffer.isBuffer('a string'); // false
  273. * Buffer.isBuffer([]); // false
  274. * Buffer.isBuffer(new Uint8Array(1024)); // false
  275. * ```
  276. * @since v0.1.101
  277. */
  278. isBuffer(obj: any): obj is Buffer;
  279. /**
  280. * Returns `true` if `encoding` is the name of a supported character encoding,
  281. * or `false` otherwise.
  282. *
  283. * ```js
  284. * import { Buffer } from 'node:buffer';
  285. *
  286. * console.log(Buffer.isEncoding('utf8'));
  287. * // Prints: true
  288. *
  289. * console.log(Buffer.isEncoding('hex'));
  290. * // Prints: true
  291. *
  292. * console.log(Buffer.isEncoding('utf/8'));
  293. * // Prints: false
  294. *
  295. * console.log(Buffer.isEncoding(''));
  296. * // Prints: false
  297. * ```
  298. * @since v0.9.1
  299. * @param encoding A character encoding name to check.
  300. */
  301. isEncoding(encoding: string): encoding is BufferEncoding;
  302. /**
  303. * Returns the byte length of a string when encoded using `encoding`.
  304. * 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
  305. * for the encoding that is used to convert the string into bytes.
  306. *
  307. * For `'base64'`, `'base64url'`, and `'hex'`, this function assumes valid input.
  308. * For strings that contain non-base64/hex-encoded data (e.g. whitespace), the
  309. * return value might be greater than the length of a `Buffer` created from the
  310. * string.
  311. *
  312. * ```js
  313. * import { Buffer } from 'node:buffer';
  314. *
  315. * const str = '\u00bd + \u00bc = \u00be';
  316. *
  317. * console.log(`${str}: ${str.length} characters, ` +
  318. * `${Buffer.byteLength(str, 'utf8')} bytes`);
  319. * // Prints: ½ + ¼ = ¾: 9 characters, 12 bytes
  320. * ```
  321. *
  322. * When `string` is a
  323. * `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/-
  324. * Reference/Global_Objects/TypedArray)/[`ArrayBuffer`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer)/[`SharedArrayBuffer`](https://develop-
  325. * er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by `.byteLength`is returned.
  326. * @since v0.1.90
  327. * @param string A value to calculate the length of.
  328. * @param [encoding='utf8'] If `string` is a string, this is its encoding.
  329. * @return The number of bytes contained within `string`.
  330. */
  331. byteLength(
  332. string: string | Buffer | NodeJS.ArrayBufferView | ArrayBuffer | SharedArrayBuffer,
  333. encoding?: BufferEncoding,
  334. ): number;
  335. /**
  336. * Compares `buf1` to `buf2`, typically for the purpose of sorting arrays of `Buffer` instances. This is equivalent to calling `buf1.compare(buf2)`.
  337. *
  338. * ```js
  339. * import { Buffer } from 'node:buffer';
  340. *
  341. * const buf1 = Buffer.from('1234');
  342. * const buf2 = Buffer.from('0123');
  343. * const arr = [buf1, buf2];
  344. *
  345. * console.log(arr.sort(Buffer.compare));
  346. * // Prints: [ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ]
  347. * // (This result is equal to: [buf2, buf1].)
  348. * ```
  349. * @since v0.11.13
  350. * @return Either `-1`, `0`, or `1`, depending on the result of the comparison. See `compare` for details.
  351. */
  352. compare(buf1: Uint8Array, buf2: Uint8Array): -1 | 0 | 1;
  353. /**
  354. * This is the size (in bytes) of pre-allocated internal `Buffer` instances used
  355. * for pooling. This value may be modified.
  356. * @since v0.11.3
  357. */
  358. poolSize: number;
  359. }
  360. interface Buffer {
  361. // see buffer.buffer.d.ts for implementation specific to TypeScript 5.7 and later
  362. // see ts5.6/buffer.buffer.d.ts for implementation specific to TypeScript 5.6 and earlier
  363. /**
  364. * 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
  365. * not contain enough space to fit the entire string, only part of `string` will be
  366. * written. However, partially encoded characters will not be written.
  367. *
  368. * ```js
  369. * import { Buffer } from 'node:buffer';
  370. *
  371. * const buf = Buffer.alloc(256);
  372. *
  373. * const len = buf.write('\u00bd + \u00bc = \u00be', 0);
  374. *
  375. * console.log(`${len} bytes: ${buf.toString('utf8', 0, len)}`);
  376. * // Prints: 12 bytes: ½ + ¼ = ¾
  377. *
  378. * const buffer = Buffer.alloc(10);
  379. *
  380. * const length = buffer.write('abcd', 8);
  381. *
  382. * console.log(`${length} bytes: ${buffer.toString('utf8', 8, 10)}`);
  383. * // Prints: 2 bytes : ab
  384. * ```
  385. * @since v0.1.90
  386. * @param string String to write to `buf`.
  387. * @param [offset=0] Number of bytes to skip before starting to write `string`.
  388. * @param [length=buf.length - offset] Maximum number of bytes to write (written bytes will not exceed `buf.length - offset`).
  389. * @param [encoding='utf8'] The character encoding of `string`.
  390. * @return Number of bytes written.
  391. */
  392. write(string: string, encoding?: BufferEncoding): number;
  393. write(string: string, offset: number, encoding?: BufferEncoding): number;
  394. write(string: string, offset: number, length: number, encoding?: BufferEncoding): number;
  395. /**
  396. * 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`.
  397. *
  398. * If `encoding` is `'utf8'` and a byte sequence in the input is not valid UTF-8,
  399. * then each invalid byte is replaced with the replacement character `U+FFFD`.
  400. *
  401. * The maximum length of a string instance (in UTF-16 code units) is available
  402. * as {@link constants.MAX_STRING_LENGTH}.
  403. *
  404. * ```js
  405. * import { Buffer } from 'node:buffer';
  406. *
  407. * const buf1 = Buffer.allocUnsafe(26);
  408. *
  409. * for (let i = 0; i < 26; i++) {
  410. * // 97 is the decimal ASCII value for 'a'.
  411. * buf1[i] = i + 97;
  412. * }
  413. *
  414. * console.log(buf1.toString('utf8'));
  415. * // Prints: abcdefghijklmnopqrstuvwxyz
  416. * console.log(buf1.toString('utf8', 0, 5));
  417. * // Prints: abcde
  418. *
  419. * const buf2 = Buffer.from('tést');
  420. *
  421. * console.log(buf2.toString('hex'));
  422. * // Prints: 74c3a97374
  423. * console.log(buf2.toString('utf8', 0, 3));
  424. * // Prints: té
  425. * console.log(buf2.toString(undefined, 0, 3));
  426. * // Prints: té
  427. * ```
  428. * @since v0.1.90
  429. * @param [encoding='utf8'] The character encoding to use.
  430. * @param [start=0] The byte offset to start decoding at.
  431. * @param [end=buf.length] The byte offset to stop decoding at (not inclusive).
  432. */
  433. toString(encoding?: BufferEncoding, start?: number, end?: number): string;
  434. /**
  435. * Returns a JSON representation of `buf`. [`JSON.stringify()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) implicitly calls
  436. * this function when stringifying a `Buffer` instance.
  437. *
  438. * `Buffer.from()` accepts objects in the format returned from this method.
  439. * In particular, `Buffer.from(buf.toJSON())` works like `Buffer.from(buf)`.
  440. *
  441. * ```js
  442. * import { Buffer } from 'node:buffer';
  443. *
  444. * const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);
  445. * const json = JSON.stringify(buf);
  446. *
  447. * console.log(json);
  448. * // Prints: {"type":"Buffer","data":[1,2,3,4,5]}
  449. *
  450. * const copy = JSON.parse(json, (key, value) => {
  451. * return value &#x26;&#x26; value.type === 'Buffer' ?
  452. * Buffer.from(value) :
  453. * value;
  454. * });
  455. *
  456. * console.log(copy);
  457. * // Prints: <Buffer 01 02 03 04 05>
  458. * ```
  459. * @since v0.9.2
  460. */
  461. toJSON(): {
  462. type: "Buffer";
  463. data: number[];
  464. };
  465. /**
  466. * Returns `true` if both `buf` and `otherBuffer` have exactly the same bytes,`false` otherwise. Equivalent to `buf.compare(otherBuffer) === 0`.
  467. *
  468. * ```js
  469. * import { Buffer } from 'node:buffer';
  470. *
  471. * const buf1 = Buffer.from('ABC');
  472. * const buf2 = Buffer.from('414243', 'hex');
  473. * const buf3 = Buffer.from('ABCD');
  474. *
  475. * console.log(buf1.equals(buf2));
  476. * // Prints: true
  477. * console.log(buf1.equals(buf3));
  478. * // Prints: false
  479. * ```
  480. * @since v0.11.13
  481. * @param otherBuffer A `Buffer` or {@link Uint8Array} with which to compare `buf`.
  482. */
  483. equals(otherBuffer: Uint8Array): boolean;
  484. /**
  485. * Compares `buf` with `target` and returns a number indicating whether `buf`comes before, after, or is the same as `target` in sort order.
  486. * Comparison is based on the actual sequence of bytes in each `Buffer`.
  487. *
  488. * * `0` is returned if `target` is the same as `buf`
  489. * * `1` is returned if `target` should come _before_`buf` when sorted.
  490. * * `-1` is returned if `target` should come _after_`buf` when sorted.
  491. *
  492. * ```js
  493. * import { Buffer } from 'node:buffer';
  494. *
  495. * const buf1 = Buffer.from('ABC');
  496. * const buf2 = Buffer.from('BCD');
  497. * const buf3 = Buffer.from('ABCD');
  498. *
  499. * console.log(buf1.compare(buf1));
  500. * // Prints: 0
  501. * console.log(buf1.compare(buf2));
  502. * // Prints: -1
  503. * console.log(buf1.compare(buf3));
  504. * // Prints: -1
  505. * console.log(buf2.compare(buf1));
  506. * // Prints: 1
  507. * console.log(buf2.compare(buf3));
  508. * // Prints: 1
  509. * console.log([buf1, buf2, buf3].sort(Buffer.compare));
  510. * // Prints: [ <Buffer 41 42 43>, <Buffer 41 42 43 44>, <Buffer 42 43 44> ]
  511. * // (This result is equal to: [buf1, buf3, buf2].)
  512. * ```
  513. *
  514. * The optional `targetStart`, `targetEnd`, `sourceStart`, and `sourceEnd` arguments can be used to limit the comparison to specific ranges within `target` and `buf` respectively.
  515. *
  516. * ```js
  517. * import { Buffer } from 'node:buffer';
  518. *
  519. * const buf1 = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8, 9]);
  520. * const buf2 = Buffer.from([5, 6, 7, 8, 9, 1, 2, 3, 4]);
  521. *
  522. * console.log(buf1.compare(buf2, 5, 9, 0, 4));
  523. * // Prints: 0
  524. * console.log(buf1.compare(buf2, 0, 6, 4));
  525. * // Prints: -1
  526. * console.log(buf1.compare(buf2, 5, 6, 5));
  527. * // Prints: 1
  528. * ```
  529. *
  530. * `ERR_OUT_OF_RANGE` is thrown if `targetStart < 0`, `sourceStart < 0`, `targetEnd > target.byteLength`, or `sourceEnd > source.byteLength`.
  531. * @since v0.11.13
  532. * @param target A `Buffer` or {@link Uint8Array} with which to compare `buf`.
  533. * @param [targetStart=0] The offset within `target` at which to begin comparison.
  534. * @param [targetEnd=target.length] The offset within `target` at which to end comparison (not inclusive).
  535. * @param [sourceStart=0] The offset within `buf` at which to begin comparison.
  536. * @param [sourceEnd=buf.length] The offset within `buf` at which to end comparison (not inclusive).
  537. */
  538. compare(
  539. target: Uint8Array,
  540. targetStart?: number,
  541. targetEnd?: number,
  542. sourceStart?: number,
  543. sourceEnd?: number,
  544. ): -1 | 0 | 1;
  545. /**
  546. * Copies data from a region of `buf` to a region in `target`, even if the `target`memory region overlaps with `buf`.
  547. *
  548. * [`TypedArray.prototype.set()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/set) performs the same operation, and is available
  549. * for all TypedArrays, including Node.js `Buffer`s, although it takes
  550. * different function arguments.
  551. *
  552. * ```js
  553. * import { Buffer } from 'node:buffer';
  554. *
  555. * // Create two `Buffer` instances.
  556. * const buf1 = Buffer.allocUnsafe(26);
  557. * const buf2 = Buffer.allocUnsafe(26).fill('!');
  558. *
  559. * for (let i = 0; i < 26; i++) {
  560. * // 97 is the decimal ASCII value for 'a'.
  561. * buf1[i] = i + 97;
  562. * }
  563. *
  564. * // Copy `buf1` bytes 16 through 19 into `buf2` starting at byte 8 of `buf2`.
  565. * buf1.copy(buf2, 8, 16, 20);
  566. * // This is equivalent to:
  567. * // buf2.set(buf1.subarray(16, 20), 8);
  568. *
  569. * console.log(buf2.toString('ascii', 0, 25));
  570. * // Prints: !!!!!!!!qrst!!!!!!!!!!!!!
  571. * ```
  572. *
  573. * ```js
  574. * import { Buffer } from 'node:buffer';
  575. *
  576. * // Create a `Buffer` and copy data from one region to an overlapping region
  577. * // within the same `Buffer`.
  578. *
  579. * const buf = Buffer.allocUnsafe(26);
  580. *
  581. * for (let i = 0; i < 26; i++) {
  582. * // 97 is the decimal ASCII value for 'a'.
  583. * buf[i] = i + 97;
  584. * }
  585. *
  586. * buf.copy(buf, 0, 4, 10);
  587. *
  588. * console.log(buf.toString());
  589. * // Prints: efghijghijklmnopqrstuvwxyz
  590. * ```
  591. * @since v0.1.90
  592. * @param target A `Buffer` or {@link Uint8Array} to copy into.
  593. * @param [targetStart=0] The offset within `target` at which to begin writing.
  594. * @param [sourceStart=0] The offset within `buf` from which to begin copying.
  595. * @param [sourceEnd=buf.length] The offset within `buf` at which to stop copying (not inclusive).
  596. * @return The number of bytes copied.
  597. */
  598. copy(target: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
  599. /**
  600. * Writes `value` to `buf` at the specified `offset` as big-endian.
  601. *
  602. * `value` is interpreted and written as a two's complement signed integer.
  603. *
  604. * ```js
  605. * import { Buffer } from 'node:buffer';
  606. *
  607. * const buf = Buffer.allocUnsafe(8);
  608. *
  609. * buf.writeBigInt64BE(0x0102030405060708n, 0);
  610. *
  611. * console.log(buf);
  612. * // Prints: <Buffer 01 02 03 04 05 06 07 08>
  613. * ```
  614. * @since v12.0.0, v10.20.0
  615. * @param value Number to be written to `buf`.
  616. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
  617. * @return `offset` plus the number of bytes written.
  618. */
  619. writeBigInt64BE(value: bigint, offset?: number): number;
  620. /**
  621. * Writes `value` to `buf` at the specified `offset` as little-endian.
  622. *
  623. * `value` is interpreted and written as a two's complement signed integer.
  624. *
  625. * ```js
  626. * import { Buffer } from 'node:buffer';
  627. *
  628. * const buf = Buffer.allocUnsafe(8);
  629. *
  630. * buf.writeBigInt64LE(0x0102030405060708n, 0);
  631. *
  632. * console.log(buf);
  633. * // Prints: <Buffer 08 07 06 05 04 03 02 01>
  634. * ```
  635. * @since v12.0.0, v10.20.0
  636. * @param value Number to be written to `buf`.
  637. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
  638. * @return `offset` plus the number of bytes written.
  639. */
  640. writeBigInt64LE(value: bigint, offset?: number): number;
  641. /**
  642. * Writes `value` to `buf` at the specified `offset` as big-endian.
  643. *
  644. * This function is also available under the `writeBigUint64BE` alias.
  645. *
  646. * ```js
  647. * import { Buffer } from 'node:buffer';
  648. *
  649. * const buf = Buffer.allocUnsafe(8);
  650. *
  651. * buf.writeBigUInt64BE(0xdecafafecacefaden, 0);
  652. *
  653. * console.log(buf);
  654. * // Prints: <Buffer de ca fa fe ca ce fa de>
  655. * ```
  656. * @since v12.0.0, v10.20.0
  657. * @param value Number to be written to `buf`.
  658. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
  659. * @return `offset` plus the number of bytes written.
  660. */
  661. writeBigUInt64BE(value: bigint, offset?: number): number;
  662. /**
  663. * @alias Buffer.writeBigUInt64BE
  664. * @since v14.10.0, v12.19.0
  665. */
  666. writeBigUint64BE(value: bigint, offset?: number): number;
  667. /**
  668. * Writes `value` to `buf` at the specified `offset` as little-endian
  669. *
  670. * ```js
  671. * import { Buffer } from 'node:buffer';
  672. *
  673. * const buf = Buffer.allocUnsafe(8);
  674. *
  675. * buf.writeBigUInt64LE(0xdecafafecacefaden, 0);
  676. *
  677. * console.log(buf);
  678. * // Prints: <Buffer de fa ce ca fe fa ca de>
  679. * ```
  680. *
  681. * This function is also available under the `writeBigUint64LE` alias.
  682. * @since v12.0.0, v10.20.0
  683. * @param value Number to be written to `buf`.
  684. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy: `0 <= offset <= buf.length - 8`.
  685. * @return `offset` plus the number of bytes written.
  686. */
  687. writeBigUInt64LE(value: bigint, offset?: number): number;
  688. /**
  689. * @alias Buffer.writeBigUInt64LE
  690. * @since v14.10.0, v12.19.0
  691. */
  692. writeBigUint64LE(value: bigint, offset?: number): number;
  693. /**
  694. * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
  695. * when `value` is anything other than an unsigned integer.
  696. *
  697. * This function is also available under the `writeUintLE` alias.
  698. *
  699. * ```js
  700. * import { Buffer } from 'node:buffer';
  701. *
  702. * const buf = Buffer.allocUnsafe(6);
  703. *
  704. * buf.writeUIntLE(0x1234567890ab, 0, 6);
  705. *
  706. * console.log(buf);
  707. * // Prints: <Buffer ab 90 78 56 34 12>
  708. * ```
  709. * @since v0.5.5
  710. * @param value Number to be written to `buf`.
  711. * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
  712. * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
  713. * @return `offset` plus the number of bytes written.
  714. */
  715. writeUIntLE(value: number, offset: number, byteLength: number): number;
  716. /**
  717. * @alias Buffer.writeUIntLE
  718. * @since v14.9.0, v12.19.0
  719. */
  720. writeUintLE(value: number, offset: number, byteLength: number): number;
  721. /**
  722. * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as big-endian. Supports up to 48 bits of accuracy. Behavior is undefined
  723. * when `value` is anything other than an unsigned integer.
  724. *
  725. * This function is also available under the `writeUintBE` alias.
  726. *
  727. * ```js
  728. * import { Buffer } from 'node:buffer';
  729. *
  730. * const buf = Buffer.allocUnsafe(6);
  731. *
  732. * buf.writeUIntBE(0x1234567890ab, 0, 6);
  733. *
  734. * console.log(buf);
  735. * // Prints: <Buffer 12 34 56 78 90 ab>
  736. * ```
  737. * @since v0.5.5
  738. * @param value Number to be written to `buf`.
  739. * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
  740. * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
  741. * @return `offset` plus the number of bytes written.
  742. */
  743. writeUIntBE(value: number, offset: number, byteLength: number): number;
  744. /**
  745. * @alias Buffer.writeUIntBE
  746. * @since v14.9.0, v12.19.0
  747. */
  748. writeUintBE(value: number, offset: number, byteLength: number): number;
  749. /**
  750. * Writes `byteLength` bytes of `value` to `buf` at the specified `offset`as little-endian. Supports up to 48 bits of accuracy. Behavior is undefined
  751. * when `value` is anything other than a signed integer.
  752. *
  753. * ```js
  754. * import { Buffer } from 'node:buffer';
  755. *
  756. * const buf = Buffer.allocUnsafe(6);
  757. *
  758. * buf.writeIntLE(0x1234567890ab, 0, 6);
  759. *
  760. * console.log(buf);
  761. * // Prints: <Buffer ab 90 78 56 34 12>
  762. * ```
  763. * @since v0.11.15
  764. * @param value Number to be written to `buf`.
  765. * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
  766. * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
  767. * @return `offset` plus the number of bytes written.
  768. */
  769. writeIntLE(value: number, offset: number, byteLength: number): number;
  770. /**
  771. * 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
  772. * signed integer.
  773. *
  774. * ```js
  775. * import { Buffer } from 'node:buffer';
  776. *
  777. * const buf = Buffer.allocUnsafe(6);
  778. *
  779. * buf.writeIntBE(0x1234567890ab, 0, 6);
  780. *
  781. * console.log(buf);
  782. * // Prints: <Buffer 12 34 56 78 90 ab>
  783. * ```
  784. * @since v0.11.15
  785. * @param value Number to be written to `buf`.
  786. * @param offset Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - byteLength`.
  787. * @param byteLength Number of bytes to write. Must satisfy `0 < byteLength <= 6`.
  788. * @return `offset` plus the number of bytes written.
  789. */
  790. writeIntBE(value: number, offset: number, byteLength: number): number;
  791. /**
  792. * Reads an unsigned, big-endian 64-bit integer from `buf` at the specified`offset`.
  793. *
  794. * This function is also available under the `readBigUint64BE` alias.
  795. *
  796. * ```js
  797. * import { Buffer } from 'node:buffer';
  798. *
  799. * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
  800. *
  801. * console.log(buf.readBigUInt64BE(0));
  802. * // Prints: 4294967295n
  803. * ```
  804. * @since v12.0.0, v10.20.0
  805. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
  806. */
  807. readBigUInt64BE(offset?: number): bigint;
  808. /**
  809. * @alias Buffer.readBigUInt64BE
  810. * @since v14.10.0, v12.19.0
  811. */
  812. readBigUint64BE(offset?: number): bigint;
  813. /**
  814. * Reads an unsigned, little-endian 64-bit integer from `buf` at the specified`offset`.
  815. *
  816. * This function is also available under the `readBigUint64LE` alias.
  817. *
  818. * ```js
  819. * import { Buffer } from 'node:buffer';
  820. *
  821. * const buf = Buffer.from([0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff]);
  822. *
  823. * console.log(buf.readBigUInt64LE(0));
  824. * // Prints: 18446744069414584320n
  825. * ```
  826. * @since v12.0.0, v10.20.0
  827. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
  828. */
  829. readBigUInt64LE(offset?: number): bigint;
  830. /**
  831. * @alias Buffer.readBigUInt64LE
  832. * @since v14.10.0, v12.19.0
  833. */
  834. readBigUint64LE(offset?: number): bigint;
  835. /**
  836. * Reads a signed, big-endian 64-bit integer from `buf` at the specified `offset`.
  837. *
  838. * Integers read from a `Buffer` are interpreted as two's complement signed
  839. * values.
  840. * @since v12.0.0, v10.20.0
  841. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
  842. */
  843. readBigInt64BE(offset?: number): bigint;
  844. /**
  845. * Reads a signed, little-endian 64-bit integer from `buf` at the specified`offset`.
  846. *
  847. * Integers read from a `Buffer` are interpreted as two's complement signed
  848. * values.
  849. * @since v12.0.0, v10.20.0
  850. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy: `0 <= offset <= buf.length - 8`.
  851. */
  852. readBigInt64LE(offset?: number): bigint;
  853. /**
  854. * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned, little-endian integer supporting
  855. * up to 48 bits of accuracy.
  856. *
  857. * This function is also available under the `readUintLE` alias.
  858. *
  859. * ```js
  860. * import { Buffer } from 'node:buffer';
  861. *
  862. * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
  863. *
  864. * console.log(buf.readUIntLE(0, 6).toString(16));
  865. * // Prints: ab9078563412
  866. * ```
  867. * @since v0.11.15
  868. * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
  869. * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
  870. */
  871. readUIntLE(offset: number, byteLength: number): number;
  872. /**
  873. * @alias Buffer.readUIntLE
  874. * @since v14.9.0, v12.19.0
  875. */
  876. readUintLE(offset: number, byteLength: number): number;
  877. /**
  878. * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as an unsigned big-endian integer supporting
  879. * up to 48 bits of accuracy.
  880. *
  881. * This function is also available under the `readUintBE` alias.
  882. *
  883. * ```js
  884. * import { Buffer } from 'node:buffer';
  885. *
  886. * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
  887. *
  888. * console.log(buf.readUIntBE(0, 6).toString(16));
  889. * // Prints: 1234567890ab
  890. * console.log(buf.readUIntBE(1, 6).toString(16));
  891. * // Throws ERR_OUT_OF_RANGE.
  892. * ```
  893. * @since v0.11.15
  894. * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
  895. * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
  896. */
  897. readUIntBE(offset: number, byteLength: number): number;
  898. /**
  899. * @alias Buffer.readUIntBE
  900. * @since v14.9.0, v12.19.0
  901. */
  902. readUintBE(offset: number, byteLength: number): number;
  903. /**
  904. * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a little-endian, two's complement signed value
  905. * supporting up to 48 bits of accuracy.
  906. *
  907. * ```js
  908. * import { Buffer } from 'node:buffer';
  909. *
  910. * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
  911. *
  912. * console.log(buf.readIntLE(0, 6).toString(16));
  913. * // Prints: -546f87a9cbee
  914. * ```
  915. * @since v0.11.15
  916. * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
  917. * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
  918. */
  919. readIntLE(offset: number, byteLength: number): number;
  920. /**
  921. * Reads `byteLength` number of bytes from `buf` at the specified `offset` and interprets the result as a big-endian, two's complement signed value
  922. * supporting up to 48 bits of accuracy.
  923. *
  924. * ```js
  925. * import { Buffer } from 'node:buffer';
  926. *
  927. * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78, 0x90, 0xab]);
  928. *
  929. * console.log(buf.readIntBE(0, 6).toString(16));
  930. * // Prints: 1234567890ab
  931. * console.log(buf.readIntBE(1, 6).toString(16));
  932. * // Throws ERR_OUT_OF_RANGE.
  933. * console.log(buf.readIntBE(1, 0).toString(16));
  934. * // Throws ERR_OUT_OF_RANGE.
  935. * ```
  936. * @since v0.11.15
  937. * @param offset Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - byteLength`.
  938. * @param byteLength Number of bytes to read. Must satisfy `0 < byteLength <= 6`.
  939. */
  940. readIntBE(offset: number, byteLength: number): number;
  941. /**
  942. * Reads an unsigned 8-bit integer from `buf` at the specified `offset`.
  943. *
  944. * This function is also available under the `readUint8` alias.
  945. *
  946. * ```js
  947. * import { Buffer } from 'node:buffer';
  948. *
  949. * const buf = Buffer.from([1, -2]);
  950. *
  951. * console.log(buf.readUInt8(0));
  952. * // Prints: 1
  953. * console.log(buf.readUInt8(1));
  954. * // Prints: 254
  955. * console.log(buf.readUInt8(2));
  956. * // Throws ERR_OUT_OF_RANGE.
  957. * ```
  958. * @since v0.5.0
  959. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
  960. */
  961. readUInt8(offset?: number): number;
  962. /**
  963. * @alias Buffer.readUInt8
  964. * @since v14.9.0, v12.19.0
  965. */
  966. readUint8(offset?: number): number;
  967. /**
  968. * Reads an unsigned, little-endian 16-bit integer from `buf` at the specified `offset`.
  969. *
  970. * This function is also available under the `readUint16LE` alias.
  971. *
  972. * ```js
  973. * import { Buffer } from 'node:buffer';
  974. *
  975. * const buf = Buffer.from([0x12, 0x34, 0x56]);
  976. *
  977. * console.log(buf.readUInt16LE(0).toString(16));
  978. * // Prints: 3412
  979. * console.log(buf.readUInt16LE(1).toString(16));
  980. * // Prints: 5634
  981. * console.log(buf.readUInt16LE(2).toString(16));
  982. * // Throws ERR_OUT_OF_RANGE.
  983. * ```
  984. * @since v0.5.5
  985. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
  986. */
  987. readUInt16LE(offset?: number): number;
  988. /**
  989. * @alias Buffer.readUInt16LE
  990. * @since v14.9.0, v12.19.0
  991. */
  992. readUint16LE(offset?: number): number;
  993. /**
  994. * Reads an unsigned, big-endian 16-bit integer from `buf` at the specified`offset`.
  995. *
  996. * This function is also available under the `readUint16BE` alias.
  997. *
  998. * ```js
  999. * import { Buffer } from 'node:buffer';
  1000. *
  1001. * const buf = Buffer.from([0x12, 0x34, 0x56]);
  1002. *
  1003. * console.log(buf.readUInt16BE(0).toString(16));
  1004. * // Prints: 1234
  1005. * console.log(buf.readUInt16BE(1).toString(16));
  1006. * // Prints: 3456
  1007. * ```
  1008. * @since v0.5.5
  1009. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
  1010. */
  1011. readUInt16BE(offset?: number): number;
  1012. /**
  1013. * @alias Buffer.readUInt16BE
  1014. * @since v14.9.0, v12.19.0
  1015. */
  1016. readUint16BE(offset?: number): number;
  1017. /**
  1018. * Reads an unsigned, little-endian 32-bit integer from `buf` at the specified`offset`.
  1019. *
  1020. * This function is also available under the `readUint32LE` alias.
  1021. *
  1022. * ```js
  1023. * import { Buffer } from 'node:buffer';
  1024. *
  1025. * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
  1026. *
  1027. * console.log(buf.readUInt32LE(0).toString(16));
  1028. * // Prints: 78563412
  1029. * console.log(buf.readUInt32LE(1).toString(16));
  1030. * // Throws ERR_OUT_OF_RANGE.
  1031. * ```
  1032. * @since v0.5.5
  1033. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
  1034. */
  1035. readUInt32LE(offset?: number): number;
  1036. /**
  1037. * @alias Buffer.readUInt32LE
  1038. * @since v14.9.0, v12.19.0
  1039. */
  1040. readUint32LE(offset?: number): number;
  1041. /**
  1042. * Reads an unsigned, big-endian 32-bit integer from `buf` at the specified`offset`.
  1043. *
  1044. * This function is also available under the `readUint32BE` alias.
  1045. *
  1046. * ```js
  1047. * import { Buffer } from 'node:buffer';
  1048. *
  1049. * const buf = Buffer.from([0x12, 0x34, 0x56, 0x78]);
  1050. *
  1051. * console.log(buf.readUInt32BE(0).toString(16));
  1052. * // Prints: 12345678
  1053. * ```
  1054. * @since v0.5.5
  1055. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
  1056. */
  1057. readUInt32BE(offset?: number): number;
  1058. /**
  1059. * @alias Buffer.readUInt32BE
  1060. * @since v14.9.0, v12.19.0
  1061. */
  1062. readUint32BE(offset?: number): number;
  1063. /**
  1064. * Reads a signed 8-bit integer from `buf` at the specified `offset`.
  1065. *
  1066. * Integers read from a `Buffer` are interpreted as two's complement signed values.
  1067. *
  1068. * ```js
  1069. * import { Buffer } from 'node:buffer';
  1070. *
  1071. * const buf = Buffer.from([-1, 5]);
  1072. *
  1073. * console.log(buf.readInt8(0));
  1074. * // Prints: -1
  1075. * console.log(buf.readInt8(1));
  1076. * // Prints: 5
  1077. * console.log(buf.readInt8(2));
  1078. * // Throws ERR_OUT_OF_RANGE.
  1079. * ```
  1080. * @since v0.5.0
  1081. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 1`.
  1082. */
  1083. readInt8(offset?: number): number;
  1084. /**
  1085. * Reads a signed, little-endian 16-bit integer from `buf` at the specified`offset`.
  1086. *
  1087. * Integers read from a `Buffer` are interpreted as two's complement signed values.
  1088. *
  1089. * ```js
  1090. * import { Buffer } from 'node:buffer';
  1091. *
  1092. * const buf = Buffer.from([0, 5]);
  1093. *
  1094. * console.log(buf.readInt16LE(0));
  1095. * // Prints: 1280
  1096. * console.log(buf.readInt16LE(1));
  1097. * // Throws ERR_OUT_OF_RANGE.
  1098. * ```
  1099. * @since v0.5.5
  1100. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
  1101. */
  1102. readInt16LE(offset?: number): number;
  1103. /**
  1104. * Reads a signed, big-endian 16-bit integer from `buf` at the specified `offset`.
  1105. *
  1106. * Integers read from a `Buffer` are interpreted as two's complement signed values.
  1107. *
  1108. * ```js
  1109. * import { Buffer } from 'node:buffer';
  1110. *
  1111. * const buf = Buffer.from([0, 5]);
  1112. *
  1113. * console.log(buf.readInt16BE(0));
  1114. * // Prints: 5
  1115. * ```
  1116. * @since v0.5.5
  1117. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 2`.
  1118. */
  1119. readInt16BE(offset?: number): number;
  1120. /**
  1121. * Reads a signed, little-endian 32-bit integer from `buf` at the specified`offset`.
  1122. *
  1123. * Integers read from a `Buffer` are interpreted as two's complement signed values.
  1124. *
  1125. * ```js
  1126. * import { Buffer } from 'node:buffer';
  1127. *
  1128. * const buf = Buffer.from([0, 0, 0, 5]);
  1129. *
  1130. * console.log(buf.readInt32LE(0));
  1131. * // Prints: 83886080
  1132. * console.log(buf.readInt32LE(1));
  1133. * // Throws ERR_OUT_OF_RANGE.
  1134. * ```
  1135. * @since v0.5.5
  1136. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
  1137. */
  1138. readInt32LE(offset?: number): number;
  1139. /**
  1140. * Reads a signed, big-endian 32-bit integer from `buf` at the specified `offset`.
  1141. *
  1142. * Integers read from a `Buffer` are interpreted as two's complement signed values.
  1143. *
  1144. * ```js
  1145. * import { Buffer } from 'node:buffer';
  1146. *
  1147. * const buf = Buffer.from([0, 0, 0, 5]);
  1148. *
  1149. * console.log(buf.readInt32BE(0));
  1150. * // Prints: 5
  1151. * ```
  1152. * @since v0.5.5
  1153. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
  1154. */
  1155. readInt32BE(offset?: number): number;
  1156. /**
  1157. * Reads a 32-bit, little-endian float from `buf` at the specified `offset`.
  1158. *
  1159. * ```js
  1160. * import { Buffer } from 'node:buffer';
  1161. *
  1162. * const buf = Buffer.from([1, 2, 3, 4]);
  1163. *
  1164. * console.log(buf.readFloatLE(0));
  1165. * // Prints: 1.539989614439558e-36
  1166. * console.log(buf.readFloatLE(1));
  1167. * // Throws ERR_OUT_OF_RANGE.
  1168. * ```
  1169. * @since v0.11.15
  1170. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
  1171. */
  1172. readFloatLE(offset?: number): number;
  1173. /**
  1174. * Reads a 32-bit, big-endian float from `buf` at the specified `offset`.
  1175. *
  1176. * ```js
  1177. * import { Buffer } from 'node:buffer';
  1178. *
  1179. * const buf = Buffer.from([1, 2, 3, 4]);
  1180. *
  1181. * console.log(buf.readFloatBE(0));
  1182. * // Prints: 2.387939260590663e-38
  1183. * ```
  1184. * @since v0.11.15
  1185. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 4`.
  1186. */
  1187. readFloatBE(offset?: number): number;
  1188. /**
  1189. * Reads a 64-bit, little-endian double from `buf` at the specified `offset`.
  1190. *
  1191. * ```js
  1192. * import { Buffer } from 'node:buffer';
  1193. *
  1194. * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
  1195. *
  1196. * console.log(buf.readDoubleLE(0));
  1197. * // Prints: 5.447603722011605e-270
  1198. * console.log(buf.readDoubleLE(1));
  1199. * // Throws ERR_OUT_OF_RANGE.
  1200. * ```
  1201. * @since v0.11.15
  1202. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
  1203. */
  1204. readDoubleLE(offset?: number): number;
  1205. /**
  1206. * Reads a 64-bit, big-endian double from `buf` at the specified `offset`.
  1207. *
  1208. * ```js
  1209. * import { Buffer } from 'node:buffer';
  1210. *
  1211. * const buf = Buffer.from([1, 2, 3, 4, 5, 6, 7, 8]);
  1212. *
  1213. * console.log(buf.readDoubleBE(0));
  1214. * // Prints: 8.20788039913184e-304
  1215. * ```
  1216. * @since v0.11.15
  1217. * @param [offset=0] Number of bytes to skip before starting to read. Must satisfy `0 <= offset <= buf.length - 8`.
  1218. */
  1219. readDoubleBE(offset?: number): number;
  1220. reverse(): this;
  1221. /**
  1222. * Interprets `buf` as an array of unsigned 16-bit integers and swaps the
  1223. * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 2.
  1224. *
  1225. * ```js
  1226. * import { Buffer } from 'node:buffer';
  1227. *
  1228. * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
  1229. *
  1230. * console.log(buf1);
  1231. * // Prints: <Buffer 01 02 03 04 05 06 07 08>
  1232. *
  1233. * buf1.swap16();
  1234. *
  1235. * console.log(buf1);
  1236. * // Prints: <Buffer 02 01 04 03 06 05 08 07>
  1237. *
  1238. * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
  1239. *
  1240. * buf2.swap16();
  1241. * // Throws ERR_INVALID_BUFFER_SIZE.
  1242. * ```
  1243. *
  1244. * One convenient use of `buf.swap16()` is to perform a fast in-place conversion
  1245. * between UTF-16 little-endian and UTF-16 big-endian:
  1246. *
  1247. * ```js
  1248. * import { Buffer } from 'node:buffer';
  1249. *
  1250. * const buf = Buffer.from('This is little-endian UTF-16', 'utf16le');
  1251. * buf.swap16(); // Convert to big-endian UTF-16 text.
  1252. * ```
  1253. * @since v5.10.0
  1254. * @return A reference to `buf`.
  1255. */
  1256. swap16(): this;
  1257. /**
  1258. * Interprets `buf` as an array of unsigned 32-bit integers and swaps the
  1259. * byte order _in-place_. Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 4.
  1260. *
  1261. * ```js
  1262. * import { Buffer } from 'node:buffer';
  1263. *
  1264. * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
  1265. *
  1266. * console.log(buf1);
  1267. * // Prints: <Buffer 01 02 03 04 05 06 07 08>
  1268. *
  1269. * buf1.swap32();
  1270. *
  1271. * console.log(buf1);
  1272. * // Prints: <Buffer 04 03 02 01 08 07 06 05>
  1273. *
  1274. * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
  1275. *
  1276. * buf2.swap32();
  1277. * // Throws ERR_INVALID_BUFFER_SIZE.
  1278. * ```
  1279. * @since v5.10.0
  1280. * @return A reference to `buf`.
  1281. */
  1282. swap32(): this;
  1283. /**
  1284. * Interprets `buf` as an array of 64-bit numbers and swaps byte order _in-place_.
  1285. * Throws `ERR_INVALID_BUFFER_SIZE` if `buf.length` is not a multiple of 8.
  1286. *
  1287. * ```js
  1288. * import { Buffer } from 'node:buffer';
  1289. *
  1290. * const buf1 = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8]);
  1291. *
  1292. * console.log(buf1);
  1293. * // Prints: <Buffer 01 02 03 04 05 06 07 08>
  1294. *
  1295. * buf1.swap64();
  1296. *
  1297. * console.log(buf1);
  1298. * // Prints: <Buffer 08 07 06 05 04 03 02 01>
  1299. *
  1300. * const buf2 = Buffer.from([0x1, 0x2, 0x3]);
  1301. *
  1302. * buf2.swap64();
  1303. * // Throws ERR_INVALID_BUFFER_SIZE.
  1304. * ```
  1305. * @since v6.3.0
  1306. * @return A reference to `buf`.
  1307. */
  1308. swap64(): this;
  1309. /**
  1310. * Writes `value` to `buf` at the specified `offset`. `value` must be a
  1311. * valid unsigned 8-bit integer. Behavior is undefined when `value` is anything
  1312. * other than an unsigned 8-bit integer.
  1313. *
  1314. * This function is also available under the `writeUint8` alias.
  1315. *
  1316. * ```js
  1317. * import { Buffer } from 'node:buffer';
  1318. *
  1319. * const buf = Buffer.allocUnsafe(4);
  1320. *
  1321. * buf.writeUInt8(0x3, 0);
  1322. * buf.writeUInt8(0x4, 1);
  1323. * buf.writeUInt8(0x23, 2);
  1324. * buf.writeUInt8(0x42, 3);
  1325. *
  1326. * console.log(buf);
  1327. * // Prints: <Buffer 03 04 23 42>
  1328. * ```
  1329. * @since v0.5.0
  1330. * @param value Number to be written to `buf`.
  1331. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
  1332. * @return `offset` plus the number of bytes written.
  1333. */
  1334. writeUInt8(value: number, offset?: number): number;
  1335. /**
  1336. * @alias Buffer.writeUInt8
  1337. * @since v14.9.0, v12.19.0
  1338. */
  1339. writeUint8(value: number, offset?: number): number;
  1340. /**
  1341. * 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
  1342. * anything other than an unsigned 16-bit integer.
  1343. *
  1344. * This function is also available under the `writeUint16LE` alias.
  1345. *
  1346. * ```js
  1347. * import { Buffer } from 'node:buffer';
  1348. *
  1349. * const buf = Buffer.allocUnsafe(4);
  1350. *
  1351. * buf.writeUInt16LE(0xdead, 0);
  1352. * buf.writeUInt16LE(0xbeef, 2);
  1353. *
  1354. * console.log(buf);
  1355. * // Prints: <Buffer ad de ef be>
  1356. * ```
  1357. * @since v0.5.5
  1358. * @param value Number to be written to `buf`.
  1359. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
  1360. * @return `offset` plus the number of bytes written.
  1361. */
  1362. writeUInt16LE(value: number, offset?: number): number;
  1363. /**
  1364. * @alias Buffer.writeUInt16LE
  1365. * @since v14.9.0, v12.19.0
  1366. */
  1367. writeUint16LE(value: number, offset?: number): number;
  1368. /**
  1369. * 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
  1370. * unsigned 16-bit integer.
  1371. *
  1372. * This function is also available under the `writeUint16BE` alias.
  1373. *
  1374. * ```js
  1375. * import { Buffer } from 'node:buffer';
  1376. *
  1377. * const buf = Buffer.allocUnsafe(4);
  1378. *
  1379. * buf.writeUInt16BE(0xdead, 0);
  1380. * buf.writeUInt16BE(0xbeef, 2);
  1381. *
  1382. * console.log(buf);
  1383. * // Prints: <Buffer de ad be ef>
  1384. * ```
  1385. * @since v0.5.5
  1386. * @param value Number to be written to `buf`.
  1387. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
  1388. * @return `offset` plus the number of bytes written.
  1389. */
  1390. writeUInt16BE(value: number, offset?: number): number;
  1391. /**
  1392. * @alias Buffer.writeUInt16BE
  1393. * @since v14.9.0, v12.19.0
  1394. */
  1395. writeUint16BE(value: number, offset?: number): number;
  1396. /**
  1397. * 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
  1398. * anything other than an unsigned 32-bit integer.
  1399. *
  1400. * This function is also available under the `writeUint32LE` alias.
  1401. *
  1402. * ```js
  1403. * import { Buffer } from 'node:buffer';
  1404. *
  1405. * const buf = Buffer.allocUnsafe(4);
  1406. *
  1407. * buf.writeUInt32LE(0xfeedface, 0);
  1408. *
  1409. * console.log(buf);
  1410. * // Prints: <Buffer ce fa ed fe>
  1411. * ```
  1412. * @since v0.5.5
  1413. * @param value Number to be written to `buf`.
  1414. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
  1415. * @return `offset` plus the number of bytes written.
  1416. */
  1417. writeUInt32LE(value: number, offset?: number): number;
  1418. /**
  1419. * @alias Buffer.writeUInt32LE
  1420. * @since v14.9.0, v12.19.0
  1421. */
  1422. writeUint32LE(value: number, offset?: number): number;
  1423. /**
  1424. * 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
  1425. * unsigned 32-bit integer.
  1426. *
  1427. * This function is also available under the `writeUint32BE` alias.
  1428. *
  1429. * ```js
  1430. * import { Buffer } from 'node:buffer';
  1431. *
  1432. * const buf = Buffer.allocUnsafe(4);
  1433. *
  1434. * buf.writeUInt32BE(0xfeedface, 0);
  1435. *
  1436. * console.log(buf);
  1437. * // Prints: <Buffer fe ed fa ce>
  1438. * ```
  1439. * @since v0.5.5
  1440. * @param value Number to be written to `buf`.
  1441. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
  1442. * @return `offset` plus the number of bytes written.
  1443. */
  1444. writeUInt32BE(value: number, offset?: number): number;
  1445. /**
  1446. * @alias Buffer.writeUInt32BE
  1447. * @since v14.9.0, v12.19.0
  1448. */
  1449. writeUint32BE(value: number, offset?: number): number;
  1450. /**
  1451. * Writes `value` to `buf` at the specified `offset`. `value` must be a valid
  1452. * signed 8-bit integer. Behavior is undefined when `value` is anything other than
  1453. * a signed 8-bit integer.
  1454. *
  1455. * `value` is interpreted and written as a two's complement signed integer.
  1456. *
  1457. * ```js
  1458. * import { Buffer } from 'node:buffer';
  1459. *
  1460. * const buf = Buffer.allocUnsafe(2);
  1461. *
  1462. * buf.writeInt8(2, 0);
  1463. * buf.writeInt8(-2, 1);
  1464. *
  1465. * console.log(buf);
  1466. * // Prints: <Buffer 02 fe>
  1467. * ```
  1468. * @since v0.5.0
  1469. * @param value Number to be written to `buf`.
  1470. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 1`.
  1471. * @return `offset` plus the number of bytes written.
  1472. */
  1473. writeInt8(value: number, offset?: number): number;
  1474. /**
  1475. * 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
  1476. * anything other than a signed 16-bit integer.
  1477. *
  1478. * The `value` is interpreted and written as a two's complement signed integer.
  1479. *
  1480. * ```js
  1481. * import { Buffer } from 'node:buffer';
  1482. *
  1483. * const buf = Buffer.allocUnsafe(2);
  1484. *
  1485. * buf.writeInt16LE(0x0304, 0);
  1486. *
  1487. * console.log(buf);
  1488. * // Prints: <Buffer 04 03>
  1489. * ```
  1490. * @since v0.5.5
  1491. * @param value Number to be written to `buf`.
  1492. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
  1493. * @return `offset` plus the number of bytes written.
  1494. */
  1495. writeInt16LE(value: number, offset?: number): number;
  1496. /**
  1497. * 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
  1498. * anything other than a signed 16-bit integer.
  1499. *
  1500. * The `value` is interpreted and written as a two's complement signed integer.
  1501. *
  1502. * ```js
  1503. * import { Buffer } from 'node:buffer';
  1504. *
  1505. * const buf = Buffer.allocUnsafe(2);
  1506. *
  1507. * buf.writeInt16BE(0x0102, 0);
  1508. *
  1509. * console.log(buf);
  1510. * // Prints: <Buffer 01 02>
  1511. * ```
  1512. * @since v0.5.5
  1513. * @param value Number to be written to `buf`.
  1514. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 2`.
  1515. * @return `offset` plus the number of bytes written.
  1516. */
  1517. writeInt16BE(value: number, offset?: number): number;
  1518. /**
  1519. * 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
  1520. * anything other than a signed 32-bit integer.
  1521. *
  1522. * The `value` is interpreted and written as a two's complement signed integer.
  1523. *
  1524. * ```js
  1525. * import { Buffer } from 'node:buffer';
  1526. *
  1527. * const buf = Buffer.allocUnsafe(4);
  1528. *
  1529. * buf.writeInt32LE(0x05060708, 0);
  1530. *
  1531. * console.log(buf);
  1532. * // Prints: <Buffer 08 07 06 05>
  1533. * ```
  1534. * @since v0.5.5
  1535. * @param value Number to be written to `buf`.
  1536. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
  1537. * @return `offset` plus the number of bytes written.
  1538. */
  1539. writeInt32LE(value: number, offset?: number): number;
  1540. /**
  1541. * 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
  1542. * anything other than a signed 32-bit integer.
  1543. *
  1544. * The `value` is interpreted and written as a two's complement signed integer.
  1545. *
  1546. * ```js
  1547. * import { Buffer } from 'node:buffer';
  1548. *
  1549. * const buf = Buffer.allocUnsafe(4);
  1550. *
  1551. * buf.writeInt32BE(0x01020304, 0);
  1552. *
  1553. * console.log(buf);
  1554. * // Prints: <Buffer 01 02 03 04>
  1555. * ```
  1556. * @since v0.5.5
  1557. * @param value Number to be written to `buf`.
  1558. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
  1559. * @return `offset` plus the number of bytes written.
  1560. */
  1561. writeInt32BE(value: number, offset?: number): number;
  1562. /**
  1563. * Writes `value` to `buf` at the specified `offset` as little-endian. Behavior is
  1564. * undefined when `value` is anything other than a JavaScript number.
  1565. *
  1566. * ```js
  1567. * import { Buffer } from 'node:buffer';
  1568. *
  1569. * const buf = Buffer.allocUnsafe(4);
  1570. *
  1571. * buf.writeFloatLE(0xcafebabe, 0);
  1572. *
  1573. * console.log(buf);
  1574. * // Prints: <Buffer bb fe 4a 4f>
  1575. * ```
  1576. * @since v0.11.15
  1577. * @param value Number to be written to `buf`.
  1578. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
  1579. * @return `offset` plus the number of bytes written.
  1580. */
  1581. writeFloatLE(value: number, offset?: number): number;
  1582. /**
  1583. * Writes `value` to `buf` at the specified `offset` as big-endian. Behavior is
  1584. * undefined when `value` is anything other than a JavaScript number.
  1585. *
  1586. * ```js
  1587. * import { Buffer } from 'node:buffer';
  1588. *
  1589. * const buf = Buffer.allocUnsafe(4);
  1590. *
  1591. * buf.writeFloatBE(0xcafebabe, 0);
  1592. *
  1593. * console.log(buf);
  1594. * // Prints: <Buffer 4f 4a fe bb>
  1595. * ```
  1596. * @since v0.11.15
  1597. * @param value Number to be written to `buf`.
  1598. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 4`.
  1599. * @return `offset` plus the number of bytes written.
  1600. */
  1601. writeFloatBE(value: number, offset?: number): number;
  1602. /**
  1603. * 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
  1604. * other than a JavaScript number.
  1605. *
  1606. * ```js
  1607. * import { Buffer } from 'node:buffer';
  1608. *
  1609. * const buf = Buffer.allocUnsafe(8);
  1610. *
  1611. * buf.writeDoubleLE(123.456, 0);
  1612. *
  1613. * console.log(buf);
  1614. * // Prints: <Buffer 77 be 9f 1a 2f dd 5e 40>
  1615. * ```
  1616. * @since v0.11.15
  1617. * @param value Number to be written to `buf`.
  1618. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
  1619. * @return `offset` plus the number of bytes written.
  1620. */
  1621. writeDoubleLE(value: number, offset?: number): number;
  1622. /**
  1623. * 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
  1624. * other than a JavaScript number.
  1625. *
  1626. * ```js
  1627. * import { Buffer } from 'node:buffer';
  1628. *
  1629. * const buf = Buffer.allocUnsafe(8);
  1630. *
  1631. * buf.writeDoubleBE(123.456, 0);
  1632. *
  1633. * console.log(buf);
  1634. * // Prints: <Buffer 40 5e dd 2f 1a 9f be 77>
  1635. * ```
  1636. * @since v0.11.15
  1637. * @param value Number to be written to `buf`.
  1638. * @param [offset=0] Number of bytes to skip before starting to write. Must satisfy `0 <= offset <= buf.length - 8`.
  1639. * @return `offset` plus the number of bytes written.
  1640. */
  1641. writeDoubleBE(value: number, offset?: number): number;
  1642. /**
  1643. * Fills `buf` with the specified `value`. If the `offset` and `end` are not given,
  1644. * the entire `buf` will be filled:
  1645. *
  1646. * ```js
  1647. * import { Buffer } from 'node:buffer';
  1648. *
  1649. * // Fill a `Buffer` with the ASCII character 'h'.
  1650. *
  1651. * const b = Buffer.allocUnsafe(50).fill('h');
  1652. *
  1653. * console.log(b.toString());
  1654. * // Prints: hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
  1655. *
  1656. * // Fill a buffer with empty string
  1657. * const c = Buffer.allocUnsafe(5).fill('');
  1658. *
  1659. * console.log(c.fill(''));
  1660. * // Prints: <Buffer 00 00 00 00 00>
  1661. * ```
  1662. *
  1663. * `value` is coerced to a `uint32` value if it is not a string, `Buffer`, or
  1664. * integer. If the resulting integer is greater than `255` (decimal), `buf` will be
  1665. * filled with `value &#x26; 255`.
  1666. *
  1667. * If the final write of a `fill()` operation falls on a multi-byte character,
  1668. * then only the bytes of that character that fit into `buf` are written:
  1669. *
  1670. * ```js
  1671. * import { Buffer } from 'node:buffer';
  1672. *
  1673. * // Fill a `Buffer` with character that takes up two bytes in UTF-8.
  1674. *
  1675. * console.log(Buffer.allocUnsafe(5).fill('\u0222'));
  1676. * // Prints: <Buffer c8 a2 c8 a2 c8>
  1677. * ```
  1678. *
  1679. * If `value` contains invalid characters, it is truncated; if no valid
  1680. * fill data remains, an exception is thrown:
  1681. *
  1682. * ```js
  1683. * import { Buffer } from 'node:buffer';
  1684. *
  1685. * const buf = Buffer.allocUnsafe(5);
  1686. *
  1687. * console.log(buf.fill('a'));
  1688. * // Prints: <Buffer 61 61 61 61 61>
  1689. * console.log(buf.fill('aazz', 'hex'));
  1690. * // Prints: <Buffer aa aa aa aa aa>
  1691. * console.log(buf.fill('zz', 'hex'));
  1692. * // Throws an exception.
  1693. * ```
  1694. * @since v0.5.0
  1695. * @param value The value with which to fill `buf`. Empty value (string, Uint8Array, Buffer) is coerced to `0`.
  1696. * @param [offset=0] Number of bytes to skip before starting to fill `buf`.
  1697. * @param [end=buf.length] Where to stop filling `buf` (not inclusive).
  1698. * @param [encoding='utf8'] The encoding for `value` if `value` is a string.
  1699. * @return A reference to `buf`.
  1700. */
  1701. fill(value: string | Uint8Array | number, offset?: number, end?: number, encoding?: BufferEncoding): this;
  1702. /**
  1703. * If `value` is:
  1704. *
  1705. * * a string, `value` is interpreted according to the character encoding in `encoding`.
  1706. * * a `Buffer` or [`Uint8Array`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array), `value` will be used in its entirety.
  1707. * To compare a partial `Buffer`, use `buf.subarray`.
  1708. * * a number, `value` will be interpreted as an unsigned 8-bit integer
  1709. * value between `0` and `255`.
  1710. *
  1711. * ```js
  1712. * import { Buffer } from 'node:buffer';
  1713. *
  1714. * const buf = Buffer.from('this is a buffer');
  1715. *
  1716. * console.log(buf.indexOf('this'));
  1717. * // Prints: 0
  1718. * console.log(buf.indexOf('is'));
  1719. * // Prints: 2
  1720. * console.log(buf.indexOf(Buffer.from('a buffer')));
  1721. * // Prints: 8
  1722. * console.log(buf.indexOf(97));
  1723. * // Prints: 8 (97 is the decimal ASCII value for 'a')
  1724. * console.log(buf.indexOf(Buffer.from('a buffer example')));
  1725. * // Prints: -1
  1726. * console.log(buf.indexOf(Buffer.from('a buffer example').slice(0, 8)));
  1727. * // Prints: 8
  1728. *
  1729. * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
  1730. *
  1731. * console.log(utf16Buffer.indexOf('\u03a3', 0, 'utf16le'));
  1732. * // Prints: 4
  1733. * console.log(utf16Buffer.indexOf('\u03a3', -4, 'utf16le'));
  1734. * // Prints: 6
  1735. * ```
  1736. *
  1737. * 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,
  1738. * an integer between 0 and 255.
  1739. *
  1740. * If `byteOffset` is not a number, it will be coerced to a number. If the result
  1741. * of coercion is `NaN` or `0`, then the entire buffer will be searched. This
  1742. * behavior matches [`String.prototype.indexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/indexOf).
  1743. *
  1744. * ```js
  1745. * import { Buffer } from 'node:buffer';
  1746. *
  1747. * const b = Buffer.from('abcdef');
  1748. *
  1749. * // Passing a value that's a number, but not a valid byte.
  1750. * // Prints: 2, equivalent to searching for 99 or 'c'.
  1751. * console.log(b.indexOf(99.9));
  1752. * console.log(b.indexOf(256 + 99));
  1753. *
  1754. * // Passing a byteOffset that coerces to NaN or 0.
  1755. * // Prints: 1, searching the whole buffer.
  1756. * console.log(b.indexOf('b', undefined));
  1757. * console.log(b.indexOf('b', {}));
  1758. * console.log(b.indexOf('b', null));
  1759. * console.log(b.indexOf('b', []));
  1760. * ```
  1761. *
  1762. * If `value` is an empty string or empty `Buffer` and `byteOffset` is less
  1763. * than `buf.length`, `byteOffset` will be returned. If `value` is empty and`byteOffset` is at least `buf.length`, `buf.length` will be returned.
  1764. * @since v1.5.0
  1765. * @param value What to search for.
  1766. * @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
  1767. * @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`.
  1768. * @return The index of the first occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
  1769. */
  1770. indexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
  1771. /**
  1772. * Identical to `buf.indexOf()`, except the last occurrence of `value` is found
  1773. * rather than the first occurrence.
  1774. *
  1775. * ```js
  1776. * import { Buffer } from 'node:buffer';
  1777. *
  1778. * const buf = Buffer.from('this buffer is a buffer');
  1779. *
  1780. * console.log(buf.lastIndexOf('this'));
  1781. * // Prints: 0
  1782. * console.log(buf.lastIndexOf('buffer'));
  1783. * // Prints: 17
  1784. * console.log(buf.lastIndexOf(Buffer.from('buffer')));
  1785. * // Prints: 17
  1786. * console.log(buf.lastIndexOf(97));
  1787. * // Prints: 15 (97 is the decimal ASCII value for 'a')
  1788. * console.log(buf.lastIndexOf(Buffer.from('yolo')));
  1789. * // Prints: -1
  1790. * console.log(buf.lastIndexOf('buffer', 5));
  1791. * // Prints: 5
  1792. * console.log(buf.lastIndexOf('buffer', 4));
  1793. * // Prints: -1
  1794. *
  1795. * const utf16Buffer = Buffer.from('\u039a\u0391\u03a3\u03a3\u0395', 'utf16le');
  1796. *
  1797. * console.log(utf16Buffer.lastIndexOf('\u03a3', undefined, 'utf16le'));
  1798. * // Prints: 6
  1799. * console.log(utf16Buffer.lastIndexOf('\u03a3', -5, 'utf16le'));
  1800. * // Prints: 4
  1801. * ```
  1802. *
  1803. * 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,
  1804. * an integer between 0 and 255.
  1805. *
  1806. * If `byteOffset` is not a number, it will be coerced to a number. Any arguments
  1807. * that coerce to `NaN`, like `{}` or `undefined`, will search the whole buffer.
  1808. * This behavior matches [`String.prototype.lastIndexOf()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/lastIndexOf).
  1809. *
  1810. * ```js
  1811. * import { Buffer } from 'node:buffer';
  1812. *
  1813. * const b = Buffer.from('abcdef');
  1814. *
  1815. * // Passing a value that's a number, but not a valid byte.
  1816. * // Prints: 2, equivalent to searching for 99 or 'c'.
  1817. * console.log(b.lastIndexOf(99.9));
  1818. * console.log(b.lastIndexOf(256 + 99));
  1819. *
  1820. * // Passing a byteOffset that coerces to NaN.
  1821. * // Prints: 1, searching the whole buffer.
  1822. * console.log(b.lastIndexOf('b', undefined));
  1823. * console.log(b.lastIndexOf('b', {}));
  1824. *
  1825. * // Passing a byteOffset that coerces to 0.
  1826. * // Prints: -1, equivalent to passing 0.
  1827. * console.log(b.lastIndexOf('b', null));
  1828. * console.log(b.lastIndexOf('b', []));
  1829. * ```
  1830. *
  1831. * If `value` is an empty string or empty `Buffer`, `byteOffset` will be returned.
  1832. * @since v6.0.0
  1833. * @param value What to search for.
  1834. * @param [byteOffset=buf.length - 1] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
  1835. * @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`.
  1836. * @return The index of the last occurrence of `value` in `buf`, or `-1` if `buf` does not contain `value`.
  1837. */
  1838. lastIndexOf(value: string | number | Uint8Array, byteOffset?: number, encoding?: BufferEncoding): number;
  1839. /**
  1840. * Equivalent to `buf.indexOf() !== -1`.
  1841. *
  1842. * ```js
  1843. * import { Buffer } from 'node:buffer';
  1844. *
  1845. * const buf = Buffer.from('this is a buffer');
  1846. *
  1847. * console.log(buf.includes('this'));
  1848. * // Prints: true
  1849. * console.log(buf.includes('is'));
  1850. * // Prints: true
  1851. * console.log(buf.includes(Buffer.from('a buffer')));
  1852. * // Prints: true
  1853. * console.log(buf.includes(97));
  1854. * // Prints: true (97 is the decimal ASCII value for 'a')
  1855. * console.log(buf.includes(Buffer.from('a buffer example')));
  1856. * // Prints: false
  1857. * console.log(buf.includes(Buffer.from('a buffer example').slice(0, 8)));
  1858. * // Prints: true
  1859. * console.log(buf.includes('this', 4));
  1860. * // Prints: false
  1861. * ```
  1862. * @since v5.3.0
  1863. * @param value What to search for.
  1864. * @param [byteOffset=0] Where to begin searching in `buf`. If negative, then offset is calculated from the end of `buf`.
  1865. * @param [encoding='utf8'] If `value` is a string, this is its encoding.
  1866. * @return `true` if `value` was found in `buf`, `false` otherwise.
  1867. */
  1868. includes(value: string | number | Buffer, byteOffset?: number, encoding?: BufferEncoding): boolean;
  1869. }
  1870. var Buffer: BufferConstructor;
  1871. /**
  1872. * Decodes a string of Base64-encoded data into bytes, and encodes those bytes
  1873. * into a string using Latin-1 (ISO-8859-1).
  1874. *
  1875. * The `data` may be any JavaScript-value that can be coerced into a string.
  1876. *
  1877. * **This function is only provided for compatibility with legacy web platform APIs**
  1878. * **and should never be used in new code, because they use strings to represent**
  1879. * **binary data and predate the introduction of typed arrays in JavaScript.**
  1880. * **For code running using Node.js APIs, converting between base64-encoded strings**
  1881. * **and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.**
  1882. * @since v15.13.0, v14.17.0
  1883. * @legacy Use `Buffer.from(data, 'base64')` instead.
  1884. * @param data The Base64-encoded input string.
  1885. */
  1886. function atob(data: string): string;
  1887. /**
  1888. * Decodes a string into bytes using Latin-1 (ISO-8859), and encodes those bytes
  1889. * into a string using Base64.
  1890. *
  1891. * The `data` may be any JavaScript-value that can be coerced into a string.
  1892. *
  1893. * **This function is only provided for compatibility with legacy web platform APIs**
  1894. * **and should never be used in new code, because they use strings to represent**
  1895. * **binary data and predate the introduction of typed arrays in JavaScript.**
  1896. * **For code running using Node.js APIs, converting between base64-encoded strings**
  1897. * **and binary data should be performed using `Buffer.from(str, 'base64')` and `buf.toString('base64')`.**
  1898. * @since v15.13.0, v14.17.0
  1899. * @legacy Use `buf.toString('base64')` instead.
  1900. * @param data An ASCII (Latin1) string.
  1901. */
  1902. function btoa(data: string): string;
  1903. interface Blob extends _Blob {}
  1904. /**
  1905. * `Blob` class is a global reference for `import { Blob } from 'node:buffer'`
  1906. * https://nodejs.org/api/buffer.html#class-blob
  1907. * @since v18.0.0
  1908. */
  1909. var Blob: typeof globalThis extends { onmessage: any; Blob: infer T } ? T
  1910. : typeof import("buffer").Blob;
  1911. interface File extends _File {}
  1912. /**
  1913. * `File` class is a global reference for `import { File } from 'node:buffer'`
  1914. * https://nodejs.org/api/buffer.html#class-file
  1915. * @since v20.0.0
  1916. */
  1917. var File: typeof globalThis extends { onmessage: any; File: infer T } ? T
  1918. : typeof import("buffer").File;
  1919. }
  1920. }
  1921. declare module "node:buffer" {
  1922. export * from "buffer";
  1923. }