Skip to content

Instantly share code, notes, and snippets.

@Shuumatsu
Created January 12, 2018 08:27
Show Gist options
  • Save Shuumatsu/ca8515196c580054e4842d2b7a7c8ec8 to your computer and use it in GitHub Desktop.
Save Shuumatsu/ca8515196c580054e4842d2b7a7c8ec8 to your computer and use it in GitHub Desktop.
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