Signal-Desktop/ts/util/arrayBufferToObjectURL.ts

20 lines
373 B
TypeScript
Raw Normal View History

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 });
2018-04-14 02:14:58 +00:00
return URL.createObjectURL(blob);
};