From 8ca5a391af8da8b99e32204bd1a5dd7f40bdc96d Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Wed, 25 Apr 2018 16:34:29 -0400 Subject: [PATCH] arrayBufferToObjectURL: Ensure `data` is `ArrayBuffer` --- ts/util/arrayBufferToObjectURL.ts | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/ts/util/arrayBufferToObjectURL.ts b/ts/util/arrayBufferToObjectURL.ts index 29bdb9eca..f9c58c8d2 100644 --- a/ts/util/arrayBufferToObjectURL.ts +++ b/ts/util/arrayBufferToObjectURL.ts @@ -1,6 +1,8 @@ /** * @prettier */ +import is from '@sindresorhus/is'; + import { MIMEType } from '../types/MIME'; export const arrayBufferToObjectURL = ({ @@ -10,6 +12,10 @@ export const arrayBufferToObjectURL = ({ data: ArrayBuffer; type: MIMEType; }): string => { + if (!is.arrayBuffer(data)) { + throw new TypeError('`data` must be an ArrayBuffer'); + } + const blob = new Blob([data], { type }); return URL.createObjectURL(blob); };