From: Martin Heidegger Date: Sat, 21 Nov 2020 02:05:07 +0000 (+0900) Subject: Types: Using Uint8Array instead of Buffer X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=7aa04d6951870fed0b021981963b48fabbc01660;p=buffer.git Types: Using Uint8Array instead of Buffer The API supports at various places to use Uint8Arrays to be used instead of Buffers. This PR loosens the type restrictions on a few instances where I noticed that an Uint8Array would suffice. --- diff --git a/index.d.ts b/index.d.ts index 5aa3549..07096a2 100644 --- a/index.d.ts +++ b/index.d.ts @@ -4,7 +4,7 @@ export class Buffer extends Uint8Array { toString(encoding?: string, start?: number, end?: number): string; toJSON(): { type: 'Buffer', data: any[] }; equals(otherBuffer: Buffer): boolean; - compare(otherBuffer: Buffer, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number; + compare(otherBuffer: Uint8Array, targetStart?: number, targetEnd?: number, sourceStart?: number, sourceEnd?: number): number; copy(targetBuffer: Buffer, targetStart?: number, sourceStart?: number, sourceEnd?: number): number; slice(start?: number, end?: number): Buffer; writeUIntLE(value: number, offset: number, byteLength: number, noAssert?: boolean): number; @@ -163,11 +163,11 @@ export class Buffer extends Uint8Array { * @param totalLength Total length of the buffers when concatenated. * If totalLength is not provided, it is read from the buffers in the list. However, this adds an additional loop to the function, so it is faster to provide the length explicitly. */ - static concat(list: Buffer[], totalLength?: number): Buffer; + static concat(list: Uint8Array[], totalLength?: number): Buffer; /** * The same as buf1.compare(buf2). */ - static compare(buf1: Buffer, buf2: Buffer): number; + static compare(buf1: Uint8Array, buf2: Uint8Array): number; /** * Allocates a new buffer of {size} octets. *