signal-desktop/ts/util/arrayBufferToObjectURL.ts
2023-01-12 12:58:53 -08:00

20 lines
434 B
TypeScript

// Copyright 2018 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { MIMEType } from '../types/MIME';
export const arrayBufferToObjectURL = ({
data,
type,
}: {
data: ArrayBuffer;
type: MIMEType;
}): string => {
if (!(data instanceof ArrayBuffer)) {
throw new TypeError('`data` must be an ArrayBuffer');
}
const blob = new Blob([data], { type });
return URL.createObjectURL(blob);
};