From 0a7bbfce6261e3933097c8f49c2a7bf71351e11f Mon Sep 17 00:00:00 2001 From: Paul Miller Date: Fri, 8 Nov 2024 15:54:23 +0000 Subject: [PATCH] Speed-up byte array checks. --- src/_assert.ts | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/_assert.ts b/src/_assert.ts index e77e0f9..d892543 100644 --- a/src/_assert.ts +++ b/src/_assert.ts @@ -7,10 +7,7 @@ function bool(b: boolean) { } export function isBytes(a: unknown): a is Uint8Array { - return ( - a instanceof Uint8Array || - (a != null && typeof a === 'object' && a.constructor.name === 'Uint8Array') - ); + return a instanceof Uint8Array || (ArrayBuffer.isView(a) && a.constructor.name === 'Uint8Array'); } function bytes(b: Uint8Array | undefined, ...lengths: number[]) {