Pinsave/counterstrike
1
1declare module "buffer" {2 type ImplicitArrayBuffer<T extends WithImplicitCoercion<ArrayBufferLike>> = T extends3 { valueOf(): infer V extends ArrayBufferLike } ? V : T;4 global {5 interface BufferConstructor {6 // see buffer.d.ts for implementation shared with all TypeScript versions7 8 /**9 * Allocates a new buffer containing the given {str}.10 *11 * @param str String to store in buffer.12 * @param encoding encoding to use, optional. Default is 'utf8'13 * @deprecated since v10.0.0 - Use `Buffer.from(string[, encoding])` instead.14 */15 new(str: string, encoding?: BufferEncoding): Buffer<ArrayBuffer>;16 /**17 * Allocates a new buffer of {size} octets.18 *19 * @param size count of octets to allocate.20 * @deprecated since v10.0.0 - Use `Buffer.alloc()` instead (also see `Buffer.allocUnsafe()`).21 */22 new(size: number): Buffer<ArrayBuffer>;23 /**24 * Allocates a new buffer containing the given {array} of octets.25 *26 * @param array The octets to store.27 * @deprecated since v10.0.0 - Use `Buffer.from(array)` instead.28 */29 new(array: ArrayLike<number>): Buffer<ArrayBuffer>;30 /**31 * Produces a Buffer backed by the same allocated memory as32 * the given {ArrayBuffer}/{SharedArrayBuffer}.33 *34 * @param arrayBuffer The ArrayBuffer with which to share memory.35 * @deprecated since v10.0.0 - Use `Buffer.from(arrayBuffer[, byteOffset[, length]])` instead.36 */37 new<TArrayBuffer extends ArrayBufferLike = ArrayBuffer>(arrayBuffer: TArrayBuffer): Buffer<TArrayBuffer>;38 /**39 * Allocates a new `Buffer` using an `array` of bytes in the range `0` – `255`.40 * Array entries outside that range will be truncated to fit into it.41 *42 * ```js43 * import { Buffer } from 'node:buffer';44 *45 * // Creates a new Buffer containing the UTF-8 bytes of the string 'buffer'.46 * const buf = Buffer.from([0x62, 0x75, 0x66, 0x66, 0x65, 0x72]);47 * ```48 *49 * If `array` is an `Array`-like object (that is, one with a `length` property of50 * type `number`), it is treated as if it is an array, unless it is a `Buffer` or51 * a `Uint8Array`. This means all other `TypedArray` variants get treated as an52 * `Array`. To create a `Buffer` from the bytes backing a `TypedArray`, use53 * `Buffer.copyBytesFrom()`.54 *55 * A `TypeError` will be thrown if `array` is not an `Array` or another type56 * appropriate for `Buffer.from()` variants.57 *58 * `Buffer.from(array)` and `Buffer.from(string)` may also use the internal59 * `Buffer` pool like `Buffer.allocUnsafe()` does.60 * @since v5.10.061 */62 from(array: WithImplicitCoercion<ArrayLike<number>>): Buffer<ArrayBuffer>;63 /**64 * This creates a view of the `ArrayBuffer` without copying the underlying65 * memory. For example, when passed a reference to the `.buffer` property of a66 * `TypedArray` instance, the newly created `Buffer` will share the same67 * allocated memory as the `TypedArray`'s underlying `ArrayBuffer`.68 *69 * ```js70 * import { Buffer } from 'node:buffer';71 *72 * const arr = new Uint16Array(2);73 *74 * arr[0] = 5000;75 * arr[1] = 4000;76 *77 * // Shares memory with `arr`.78 * const buf = Buffer.from(arr.buffer);79 *80 * console.log(buf);81 * // Prints: <Buffer 88 13 a0 0f>82 *83 * // Changing the original Uint16Array changes the Buffer also.84 * arr[1] = 6000;85 *86 * console.log(buf);87 * // Prints: <Buffer 88 13 70 17>88 * ```89 *90 * The optional `byteOffset` and `length` arguments specify a memory range within91 * the `arrayBuffer` that will be shared by the `Buffer`.92 *93 * ```js94 * import { Buffer } from 'node:buffer';95 *96 * const ab = new ArrayBuffer(10);97 * const buf = Buffer.from(ab, 0, 2);98 *99 * console.log(buf.length);100 * // Prints: 2101 * ```102 *103 * A `TypeError` will be thrown if `arrayBuffer` is not an `ArrayBuffer` or a104 * `SharedArrayBuffer` or another type appropriate for `Buffer.from()`105 * variants.106 *107 * It is important to remember that a backing `ArrayBuffer` can cover a range108 * of memory that extends beyond the bounds of a `TypedArray` view. A new109 * `Buffer` created using the `buffer` property of a `TypedArray` may extend110 * beyond the range of the `TypedArray`:111 *112 * ```js113 * import { Buffer } from 'node:buffer';114 *115 * const arrA = Uint8Array.from([0x63, 0x64, 0x65, 0x66]); // 4 elements116 * const arrB = new Uint8Array(arrA.buffer, 1, 2); // 2 elements117 * console.log(arrA.buffer === arrB.buffer); // true118 *119 * const buf = Buffer.from(arrB.buffer);120 * console.log(buf);121 * // Prints: <Buffer 63 64 65 66>122 * ```123 * @since v5.10.0124 * @param arrayBuffer An `ArrayBuffer`, `SharedArrayBuffer`, for example the125 * `.buffer` property of a `TypedArray`.126 * @param byteOffset Index of first byte to expose. **Default:** `0`.127 * @param length Number of bytes to expose. **Default:**128 * `arrayBuffer.byteLength - byteOffset`.129 */130 from<TArrayBuffer extends WithImplicitCoercion<ArrayBufferLike>>(131 arrayBuffer: TArrayBuffer,132 byteOffset?: number,133 length?: number,134 ): Buffer<ImplicitArrayBuffer<TArrayBuffer>>;135 /**136 * Creates a new `Buffer` containing `string`. The `encoding` parameter identifies137 * the character encoding to be used when converting `string` into bytes.138 *139 * ```js140 * import { Buffer } from 'node:buffer';141 *142 * const buf1 = Buffer.from('this is a tést');143 * const buf2 = Buffer.from('7468697320697320612074c3a97374', 'hex');144 *145 * console.log(buf1.toString());146 * // Prints: this is a tést147 * console.log(buf2.toString());148 * // Prints: this is a tést149 * console.log(buf1.toString('latin1'));150 * // Prints: this is a tést151 * ```152 *153 * A `TypeError` will be thrown if `string` is not a string or another type154 * appropriate for `Buffer.from()` variants.155 *156 * `Buffer.from(string)` may also use the internal `Buffer` pool like157 * `Buffer.allocUnsafe()` does.158 * @since v5.10.0159 * @param string A string to encode.160 * @param encoding The encoding of `string`. **Default:** `'utf8'`.161 */162 from(string: WithImplicitCoercion<string>, encoding?: BufferEncoding): Buffer<ArrayBuffer>;163 from(arrayOrString: WithImplicitCoercion<ArrayLike<number> | string>): Buffer<ArrayBuffer>;164 /**165 * Creates a new Buffer using the passed {data}166 * @param values to create a new Buffer167 */168 of(...items: number[]): Buffer<ArrayBuffer>;169 /**170 * Returns a new `Buffer` which is the result of concatenating all the `Buffer` instances in the `list` together.171 *172 * If the list has no items, or if the `totalLength` is 0, then a new zero-length `Buffer` is returned.173 *174 * If `totalLength` is not provided, it is calculated from the `Buffer` instances175 * in `list` by adding their lengths.176 *177 * If `totalLength` is provided, it is coerced to an unsigned integer. If the178 * combined length of the `Buffer`s in `list` exceeds `totalLength`, the result is179 * truncated to `totalLength`. If the combined length of the `Buffer`s in `list` is180 * less than `totalLength`, the remaining space is filled with zeros.181 *182 * ```js183 * import { Buffer } from 'node:buffer';184 *185 * // Create a single `Buffer` from a list of three `Buffer` instances.186 *187 * const buf1 = Buffer.alloc(10);188 * const buf2 = Buffer.alloc(14);189 * const buf3 = Buffer.alloc(18);190 * const totalLength = buf1.length + buf2.length + buf3.length;191 *192 * console.log(totalLength);193 * // Prints: 42194 *195 * const bufA = Buffer.concat([buf1, buf2, buf3], totalLength);196 *197 * console.log(bufA);198 * // Prints: <Buffer 00 00 00 00 ...>199 * console.log(bufA.length);200 * // Prints: 42201 * ```202 *203 * `Buffer.concat()` may also use the internal `Buffer` pool like `Buffer.allocUnsafe()` does.204 * @since v0.7.11205 * @param list List of `Buffer` or {@link Uint8Array} instances to concatenate.206 * @param totalLength Total length of the `Buffer` instances in `list` when concatenated.207 */208 concat(list: readonly Uint8Array[], totalLength?: number): Buffer<ArrayBuffer>;209 /**210 * Copies the underlying memory of `view` into a new `Buffer`.211 *212 * ```js213 * const u16 = new Uint16Array([0, 0xffff]);214 * const buf = Buffer.copyBytesFrom(u16, 1, 1);215 * u16[1] = 0;216 * console.log(buf.length); // 2217 * console.log(buf[0]); // 255218 * console.log(buf[1]); // 255219 * ```220 * @since v19.8.0221 * @param view The {TypedArray} to copy.222 * @param [offset=0] The starting offset within `view`.223 * @param [length=view.length - offset] The number of elements from `view` to copy.224 */225 copyBytesFrom(view: NodeJS.TypedArray, offset?: number, length?: number): Buffer<ArrayBuffer>;226 /**227 * Allocates a new `Buffer` of `size` bytes. If `fill` is `undefined`, the`Buffer` will be zero-filled.228 *229 * ```js230 * import { Buffer } from 'node:buffer';231 *232 * const buf = Buffer.alloc(5);233 *234 * console.log(buf);235 * // Prints: <Buffer 00 00 00 00 00>236 * ```237 *238 * If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.239 *240 * If `fill` is specified, the allocated `Buffer` will be initialized by calling `buf.fill(fill)`.241 *242 * ```js243 * import { Buffer } from 'node:buffer';244 *245 * const buf = Buffer.alloc(5, 'a');246 *247 * console.log(buf);248 * // Prints: <Buffer 61 61 61 61 61>249 * ```250 *251 * If both `fill` and `encoding` are specified, the allocated `Buffer` will be252 * initialized by calling `buf.fill(fill, encoding)`.253 *254 * ```js255 * import { Buffer } from 'node:buffer';256 *257 * const buf = Buffer.alloc(11, 'aGVsbG8gd29ybGQ=', 'base64');258 *259 * console.log(buf);260 * // Prints: <Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64>261 * ```262 *263 * Calling `Buffer.alloc()` can be measurably slower than the alternative `Buffer.allocUnsafe()` but ensures that the newly created `Buffer` instance264 * contents will never contain sensitive data from previous allocations, including265 * data that might not have been allocated for `Buffer`s.266 *267 * A `TypeError` will be thrown if `size` is not a number.268 * @since v5.10.0269 * @param size The desired length of the new `Buffer`.270 * @param [fill=0] A value to pre-fill the new `Buffer` with.271 * @param [encoding='utf8'] If `fill` is a string, this is its encoding.272 */273 alloc(size: number, fill?: string | Uint8Array | number, encoding?: BufferEncoding): Buffer<ArrayBuffer>;274 /**275 * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown.276 *277 * The underlying memory for `Buffer` instances created in this way is _not_278 * _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `Buffer.alloc()` instead to initialize`Buffer` instances with zeroes.279 *280 * ```js281 * import { Buffer } from 'node:buffer';282 *283 * const buf = Buffer.allocUnsafe(10);284 *285 * console.log(buf);286 * // Prints (contents may vary): <Buffer a0 8b 28 3f 01 00 00 00 50 32>287 *288 * buf.fill(0);289 *290 * console.log(buf);291 * // Prints: <Buffer 00 00 00 00 00 00 00 00 00 00>292 * ```293 *294 * A `TypeError` will be thrown if `size` is not a number.295 *296 * The `Buffer` module pre-allocates an internal `Buffer` instance of297 * size `Buffer.poolSize` that is used as a pool for the fast allocation of new `Buffer` instances created using `Buffer.allocUnsafe()`, `Buffer.from(array)`,298 * and `Buffer.concat()` only when `size` is less than `Buffer.poolSize >>> 1` (floor of `Buffer.poolSize` divided by two).299 *300 * Use of this pre-allocated internal memory pool is a key difference between301 * calling `Buffer.alloc(size, fill)` vs. `Buffer.allocUnsafe(size).fill(fill)`.302 * Specifically, `Buffer.alloc(size, fill)` will _never_ use the internal `Buffer`pool, while `Buffer.allocUnsafe(size).fill(fill)`_will_ use the internal`Buffer` pool if `size` is less303 * than or equal to half `Buffer.poolSize`. The304 * difference is subtle but can be important when an application requires the305 * additional performance that `Buffer.allocUnsafe()` provides.306 * @since v5.10.0307 * @param size The desired length of the new `Buffer`.308 */309 allocUnsafe(size: number): Buffer<ArrayBuffer>;310 /**311 * Allocates a new `Buffer` of `size` bytes. If `size` is larger than {@link constants.MAX_LENGTH} or smaller than 0, `ERR_OUT_OF_RANGE` is thrown. A zero-length `Buffer` is created if312 * `size` is 0.313 *314 * The underlying memory for `Buffer` instances created in this way is _not_315 * _initialized_. The contents of the newly created `Buffer` are unknown and _may contain sensitive data_. Use `buf.fill(0)` to initialize316 * such `Buffer` instances with zeroes.317 *318 * When using `Buffer.allocUnsafe()` to allocate new `Buffer` instances,319 * allocations under 4 KiB are sliced from a single pre-allocated `Buffer`. This320 * allows applications to avoid the garbage collection overhead of creating many321 * individually allocated `Buffer` instances. This approach improves both322 * performance and memory usage by eliminating the need to track and clean up as323 * many individual `ArrayBuffer` objects.324 *325 * However, in the case where a developer may need to retain a small chunk of326 * memory from a pool for an indeterminate amount of time, it may be appropriate327 * to create an un-pooled `Buffer` instance using `Buffer.allocUnsafeSlow()` and328 * then copying out the relevant bits.329 *330 * ```js331 * import { Buffer } from 'node:buffer';332 *333 * // Need to keep around a few small chunks of memory.334 * const store = [];335 *336 * socket.on('readable', () => {337 * let data;338 * while (null !== (data = readable.read())) {339 * // Allocate for retained data.340 * const sb = Buffer.allocUnsafeSlow(10);341 *342 * // Copy the data into the new allocation.343 * data.copy(sb, 0, 0, 10);344 *345 * store.push(sb);346 * }347 * });348 * ```349 *350 * A `TypeError` will be thrown if `size` is not a number.351 * @since v5.12.0352 * @param size The desired length of the new `Buffer`.353 */354 allocUnsafeSlow(size: number): Buffer<ArrayBuffer>;355 }356 interface Buffer<TArrayBuffer extends ArrayBufferLike = ArrayBufferLike> extends Uint8Array<TArrayBuffer> {357 // see buffer.d.ts for implementation shared with all TypeScript versions358 359 /**360 * Returns a new `Buffer` that references the same memory as the original, but361 * offset and cropped by the `start` and `end` indices.362 *363 * This method is not compatible with the `Uint8Array.prototype.slice()`,364 * which is a superclass of `Buffer`. To copy the slice, use`Uint8Array.prototype.slice()`.365 *366 * ```js367 * import { Buffer } from 'node:buffer';368 *369 * const buf = Buffer.from('buffer');370 *371 * const copiedBuf = Uint8Array.prototype.slice.call(buf);372 * copiedBuf[0]++;373 * console.log(copiedBuf.toString());374 * // Prints: cuffer375 *376 * console.log(buf.toString());377 * // Prints: buffer378 *379 * // With buf.slice(), the original buffer is modified.380 * const notReallyCopiedBuf = buf.slice();381 * notReallyCopiedBuf[0]++;382 * console.log(notReallyCopiedBuf.toString());383 * // Prints: cuffer384 * console.log(buf.toString());385 * // Also prints: cuffer (!)386 * ```387 * @since v0.3.0388 * @deprecated Use `subarray` instead.389 * @param [start=0] Where the new `Buffer` will start.390 * @param [end=buf.length] Where the new `Buffer` will end (not inclusive).391 */392 slice(start?: number, end?: number): Buffer<ArrayBuffer>;393 /**394 * Returns a new `Buffer` that references the same memory as the original, but395 * offset and cropped by the `start` and `end` indices.396 *397 * Specifying `end` greater than `buf.length` will return the same result as398 * that of `end` equal to `buf.length`.399 *400 * This method is inherited from [`TypedArray.prototype.subarray()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray).401 *402 * Modifying the new `Buffer` slice will modify the memory in the original `Buffer`because the allocated memory of the two objects overlap.403 *404 * ```js405 * import { Buffer } from 'node:buffer';406 *407 * // Create a `Buffer` with the ASCII alphabet, take a slice, and modify one byte408 * // from the original `Buffer`.409 *410 * const buf1 = Buffer.allocUnsafe(26);411 *412 * for (let i = 0; i < 26; i++) {413 * // 97 is the decimal ASCII value for 'a'.414 * buf1[i] = i + 97;415 * }416 *417 * const buf2 = buf1.subarray(0, 3);418 *419 * console.log(buf2.toString('ascii', 0, buf2.length));420 * // Prints: abc421 *422 * buf1[0] = 33;423 *424 * console.log(buf2.toString('ascii', 0, buf2.length));425 * // Prints: !bc426 * ```427 *428 * Specifying negative indexes causes the slice to be generated relative to the429 * end of `buf` rather than the beginning.430 *431 * ```js432 * import { Buffer } from 'node:buffer';433 *434 * const buf = Buffer.from('buffer');435 *436 * console.log(buf.subarray(-6, -1).toString());437 * // Prints: buffe438 * // (Equivalent to buf.subarray(0, 5).)439 *440 * console.log(buf.subarray(-6, -2).toString());441 * // Prints: buff442 * // (Equivalent to buf.subarray(0, 4).)443 *444 * console.log(buf.subarray(-5, -2).toString());445 * // Prints: uff446 * // (Equivalent to buf.subarray(1, 4).)447 * ```448 * @since v3.0.0449 * @param [start=0] Where the new `Buffer` will start.450 * @param [end=buf.length] Where the new `Buffer` will end (not inclusive).451 */452 subarray(start?: number, end?: number): Buffer<TArrayBuffer>;453 }454 type NonSharedBuffer = Buffer<ArrayBuffer>;455 type AllowSharedBuffer = Buffer<ArrayBufferLike>;456 }457 /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */458 var SlowBuffer: {459 /** @deprecated Use `Buffer.allocUnsafeSlow()` instead. */460 new(size: number): Buffer<ArrayBuffer>;461 prototype: Buffer;462 };463}464 