signal-desktop/ts/util/arrayBufferToObjectURL.ts

21 lines
434 B
TypeScript
Raw Normal View History

2023-01-03 11:55:46 -08:00
// Copyright 2018 Signal Messenger, LLC
2020-10-30 15:34:04 -05:00
// SPDX-License-Identifier: AGPL-3.0-only
import type { MIMEType } from '../types/MIME';
2018-04-13 22:14:58 -04:00
export const arrayBufferToObjectURL = ({
data,
type,
}: {
data: ArrayBuffer;
type: MIMEType;
}): string => {
2023-01-12 12:58:53 -08:00
if (!(data instanceof ArrayBuffer)) {
throw new TypeError('`data` must be an ArrayBuffer');
}
2018-04-13 22:14:58 -04:00
const blob = new Blob([data], { type });
2018-04-13 22:14:58 -04:00
return URL.createObjectURL(blob);
};