arrayBufferToObjectURL: Ensure data
is ArrayBuffer
This commit is contained in:
parent
b27fdd1559
commit
8ca5a391af
1 changed files with 6 additions and 0 deletions
|
@ -1,6 +1,8 @@
|
||||||
/**
|
/**
|
||||||
* @prettier
|
* @prettier
|
||||||
*/
|
*/
|
||||||
|
import is from '@sindresorhus/is';
|
||||||
|
|
||||||
import { MIMEType } from '../types/MIME';
|
import { MIMEType } from '../types/MIME';
|
||||||
|
|
||||||
export const arrayBufferToObjectURL = ({
|
export const arrayBufferToObjectURL = ({
|
||||||
|
@ -10,6 +12,10 @@ export const arrayBufferToObjectURL = ({
|
||||||
data: ArrayBuffer;
|
data: ArrayBuffer;
|
||||||
type: MIMEType;
|
type: MIMEType;
|
||||||
}): string => {
|
}): string => {
|
||||||
|
if (!is.arrayBuffer(data)) {
|
||||||
|
throw new TypeError('`data` must be an ArrayBuffer');
|
||||||
|
}
|
||||||
|
|
||||||
const blob = new Blob([data], { type });
|
const blob = new Blob([data], { type });
|
||||||
return URL.createObjectURL(blob);
|
return URL.createObjectURL(blob);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue