diff --git a/packages/core/src/utils/objects/isBuffer.spec.ts b/packages/core/src/utils/objects/isBuffer.spec.ts index 8f7129b60d9..1a87349602d 100644 --- a/packages/core/src/utils/objects/isBuffer.spec.ts +++ b/packages/core/src/utils/objects/isBuffer.spec.ts @@ -1,9 +1,11 @@ -import {isBuffer} from "./isBuffer"; +import {isBuffer, isUint8Array} from "./isBuffer"; describe("isBuffer", () => { it("should return true", () => { expect(isBuffer(Buffer.from(""))).toBeTruthy(); expect(isBuffer(Buffer)).toBeTruthy(); + expect(isUint8Array(Uint8Array)).toBeTruthy(); + expect(isUint8Array(Uint8Array.from([0, 1]))).toBeTruthy(); }); it("should return false", () => { expect(isBuffer({})).toBeFalsy(); diff --git a/packages/core/src/utils/objects/isBuffer.ts b/packages/core/src/utils/objects/isBuffer.ts index 1665dae062b..7b929d58b23 100644 --- a/packages/core/src/utils/objects/isBuffer.ts +++ b/packages/core/src/utils/objects/isBuffer.ts @@ -1,8 +1,19 @@ +import {nameOf} from "./nameOf"; + /** * Tests to see if the object is Buffer * @param target * @returns {boolean} */ export function isBuffer(target: any): target is Buffer { - return !!(target && (target === Buffer || target instanceof Buffer)); + // is Class + if (target && typeof target === "object" && typeof target.isBuffer === "function") { + return true; + } + + return isUint8Array(target); +} + +export function isUint8Array(target: any): target is Uint8Array { + return !!(target && (target === Uint8Array || target instanceof Uint8Array)); }