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
|
|
|
|
|
2021-10-26 14:15:33 -05:00
|
|
|
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)) {
|
2018-04-25 16:34:29 -04:00
|
|
|
throw new TypeError('`data` must be an ArrayBuffer');
|
|
|
|
}
|
|
|
|
|
2018-04-13 22:14:58 -04:00
|
|
|
const blob = new Blob([data], { type });
|
2018-05-22 12:31:43 -07:00
|
|
|
|
2018-04-13 22:14:58 -04:00
|
|
|
return URL.createObjectURL(blob);
|
|
|
|
};
|