Skip to content

Commit

Permalink
Speed-up byte array checks.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulmillr committed Nov 8, 2024
1 parent aefa866 commit 0a7bbfc
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions src/_assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]) {
Expand Down

0 comments on commit 0a7bbfc

Please sign in to comment.