signal-desktop/ts/util/arrayBufferToObjectURL.ts

22 lines
393 B
TypeScript
Raw Normal View History

2018-04-14 02:14:58 +00:00
/**
* @prettier
*/
import is from '@sindresorhus/is';
2018-04-14 02:14:58 +00:00
import { MIMEType } from '../types/MIME';
export const arrayBufferToObjectURL = ({
data,
type,
}: {
data: ArrayBuffer;
type: MIMEType;
}): string => {
if (!is.arrayBuffer(data)) {
throw new TypeError('`data` must be an ArrayBuffer');
}
2018-04-14 02:14:58 +00:00
const blob = new Blob([data], { type });
return URL.createObjectURL(blob);
};