mirror of
https://github.com/FlipsideCrypto/DefinitelyTyped.git
synced 2026-02-06 19:07:08 +00:00
@types/node: add doc to Buffer#slice and Buffer#subarray (and fix the type of Buffer#subarray) (#35998)
* add doc to Buffer#slice and Buffer#subarray * add tests for Buffer#subarray()
This commit is contained in:
parent
7ee6546bde
commit
022dbd5d91
20
types/node/globals.d.ts
vendored
20
types/node/globals.d.ts
vendored
@ -244,8 +244,24 @@ interface Buffer extends Uint8Array {
|
||||
equals(otherBuffer: Uint8Array): boolean;
|
||||
compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number;
|
||||
copy(targetBuffer: Uint8Array, targetStart?: number, sourceStart?: number, sourceEnd?: number): number;
|
||||
slice(start?: number, end?: number): Buffer;
|
||||
subarray(begin: number, end?: number): Buffer;
|
||||
/**
|
||||
* Returns a new `Buffer` that references **the same memory as the original**, but offset and cropped by the start and end indices.
|
||||
*
|
||||
* This method is incompatible with `Uint8Array#slice()`, which returns a copy of the original memory.
|
||||
*
|
||||
* @param begin Where the new `Buffer` will start. Default: `0`.
|
||||
* @param end Where the new `Buffer` will end (not inclusive). Default: `buf.length`.
|
||||
*/
|
||||
slice(begin?: number, end?: number): Buffer;
|
||||
/**
|
||||
* Returns a new `Buffer` that references **the same memory as the original**, but offset and cropped by the start and end indices.
|
||||
*
|
||||
* This method is compatible with `Uint8Array#subarray()`.
|
||||
*
|
||||
* @param begin Where the new `Buffer` will start. Default: `0`.
|
||||
* @param end Where the new `Buffer` will end (not inclusive). Default: `buf.length`.
|
||||
*/
|
||||
subarray(begin?: number, end?: number): Buffer;
|
||||
writeUIntLE(value: number, offset: number, byteLength: number): number;
|
||||
writeUIntBE(value: number, offset: number, byteLength: number): number;
|
||||
writeIntLE(value: number, offset: number, byteLength: number): number;
|
||||
|
||||
@ -207,7 +207,9 @@ b.fill('a').fill('b');
|
||||
{
|
||||
const b = Buffer.from('asd');
|
||||
let res: Buffer = b.reverse();
|
||||
res = b.subarray();
|
||||
res = b.subarray(1);
|
||||
res = b.subarray(1, 2);
|
||||
}
|
||||
|
||||
// Buffer module, transcode function
|
||||
|
||||
Loading…
Reference in New Issue
Block a user