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