3b4af17f88b3acf0cbeb8e41394e27e0315017dfc2a9e823e5b01a4cbcf1c9fc43d198dfcaed6098782ae676efe96d99546645e8b90d38763b8cf28d1c9e6a 86 KB

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