Files
Desktop/ts/util/arrayBufferToObjectURL.std.ts
2026-03-30 12:42:37 -07:00

21 lines
441 B
TypeScript

// Copyright 2018 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import type { MIMEType } from '../types/MIME.std.ts';
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);
};