From cad5e417f39c90a64b66a3e267e665d980fe6bee Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Fri, 13 Apr 2018 22:14:58 -0400 Subject: [PATCH] Add `arrayBufferToObjectURL` module --- ts/util/arrayBufferToObjectURL.ts | 15 +++++++++++++++ ts/util/index.ts | 3 ++- 2 files changed, 17 insertions(+), 1 deletion(-) create mode 100644 ts/util/arrayBufferToObjectURL.ts diff --git a/ts/util/arrayBufferToObjectURL.ts b/ts/util/arrayBufferToObjectURL.ts new file mode 100644 index 000000000..29bdb9eca --- /dev/null +++ b/ts/util/arrayBufferToObjectURL.ts @@ -0,0 +1,15 @@ +/** + * @prettier + */ +import { MIMEType } from '../types/MIME'; + +export const arrayBufferToObjectURL = ({ + data, + type, +}: { + data: ArrayBuffer; + type: MIMEType; +}): string => { + const blob = new Blob([data], { type }); + return URL.createObjectURL(blob); +}; diff --git a/ts/util/index.ts b/ts/util/index.ts index 9376b0e0b..03e5af330 100644 --- a/ts/util/index.ts +++ b/ts/util/index.ts @@ -2,6 +2,7 @@ * @prettier */ import * as GoogleChrome from './GoogleChrome'; +import { arrayBufferToObjectURL } from './arrayBufferToObjectURL'; import { missingCaseError } from './missingCaseError'; -export { GoogleChrome, missingCaseError }; +export { arrayBufferToObjectURL, GoogleChrome, missingCaseError };