From 4a9d5077f8236d38c8ec7c383211e591558bec85 Mon Sep 17 00:00:00 2001 From: Joe Hildebrand Date: Fri, 25 Oct 2024 07:14:34 -0600 Subject: [PATCH] Allow any ArrayBufferView in decode. Fixes #176 --- packages/cbor-web/types/lib/decoder.d.ts | 2 +- packages/cbor/lib/decoder.js | 2 +- packages/cbor/test/decoder.ava.js | 1 + packages/cbor/types/lib/decoder.d.ts | 2 +- 4 files changed, 4 insertions(+), 3 deletions(-) diff --git a/packages/cbor-web/types/lib/decoder.d.ts b/packages/cbor-web/types/lib/decoder.d.ts index 58507ab..2fe7e4d 100644 --- a/packages/cbor-web/types/lib/decoder.d.ts +++ b/packages/cbor-web/types/lib/decoder.d.ts @@ -127,7 +127,7 @@ declare const NOT_FOUND: unique symbol; /** * Things that can act as inputs, from which a NoFilter can be created. */ -type BufferLike = string | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray | DataView | import("stream").Readable; +type BufferLike = string | Buffer | ArrayBuffer | ArrayBufferView | DataView | import("stream").Readable; type ExtendedResults = { /** * The value that was found. diff --git a/packages/cbor/lib/decoder.js b/packages/cbor/lib/decoder.js index 68d27b0..559fcd3 100644 --- a/packages/cbor/lib/decoder.js +++ b/packages/cbor/lib/decoder.js @@ -44,7 +44,7 @@ class UnexpectedDataError extends Error { /** * Things that can act as inputs, from which a NoFilter can be created. * - * @typedef {string|Buffer|ArrayBuffer|Uint8Array|Uint8ClampedArray + * @typedef {string|Buffer|ArrayBuffer|ArrayBufferView * |DataView|import('stream').Readable} BufferLike */ /** diff --git a/packages/cbor/test/decoder.ava.js b/packages/cbor/test/decoder.ava.js index 0e0fb53..18bfbcc 100644 --- a/packages/cbor/test/decoder.ava.js +++ b/packages/cbor/test/decoder.ava.js @@ -230,6 +230,7 @@ test('typed arrays', t => { t.is(cbor.decode(ab), 9007199254740992n); t.is(cbor.decode(new Uint8Array(ab)), 9007199254740992n); t.is(cbor.decode(new Uint8ClampedArray(ab)), 9007199254740992n); + t.is(cbor.decode(new Int8Array(ab)), 9007199254740992n); // Beware endian-ness const u8b = new Uint8ClampedArray([0x61, 0x62]); diff --git a/packages/cbor/types/lib/decoder.d.ts b/packages/cbor/types/lib/decoder.d.ts index 58507ab..2fe7e4d 100644 --- a/packages/cbor/types/lib/decoder.d.ts +++ b/packages/cbor/types/lib/decoder.d.ts @@ -127,7 +127,7 @@ declare const NOT_FOUND: unique symbol; /** * Things that can act as inputs, from which a NoFilter can be created. */ -type BufferLike = string | Buffer | ArrayBuffer | Uint8Array | Uint8ClampedArray | DataView | import("stream").Readable; +type BufferLike = string | Buffer | ArrayBuffer | ArrayBufferView | DataView | import("stream").Readable; type ExtendedResults = { /** * The value that was found.