signal-desktop/ts/util/arrayBufferToObjectURL.ts

21 lines
434 B
TypeScript
Raw Normal View History

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
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)) {
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);
};