Created
January 12, 2018 08:27
-
-
Save Shuumatsu/ca8515196c580054e4842d2b7a7c8ec8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const cache = new WeakMap() | |
export default async fileblob => new Promise((resolve, reject) => { | |
if (cache.has(fileblob)) | |
resolve(cache.get(fileblob)) | |
const reader = new FileReader() | |
reader.addEventListener('load', e => { | |
const src = e.target.result | |
cache.set(fileblob, src) | |
resolve(src) | |
}) | |
reader.addEventListener('error', reject) | |
reader.readAsDataURL(fileblob) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment