]> zoso.dev Git - buffer.git/commitdiff
Types: Using Uint8Array instead of Buffer
authorMartin Heidegger <martin.heidegger@gmail.com>
Sat, 21 Nov 2020 02:05:07 +0000 (11:05 +0900)
committerGitHub <noreply@github.com>
Sat, 21 Nov 2020 02:05:07 +0000 (11:05 +0900)
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.

index.d.ts

index 5aa3549fa439baebaf5380c7cabaf86fd0eb0f31..07096a2f725aaccf84776b5e8158ac95038484cf 100644 (file)
@@ -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.
      *