@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:
FUJI Goro 2019-06-07 08:11:59 +09:00 committed by Andrew Casey
parent 7ee6546bde
commit 022dbd5d91
2 changed files with 20 additions and 2 deletions

View File

@ -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;

View File

@ -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