Skip to content

Commit

Permalink
fix: esm-modules break because Buffer is not available
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis committed Feb 3, 2021
1 parent ad42f1f commit 24cd918
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/helpers/base64.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ function fixBinary(bin) {
}

// polyfill for SSR as atob is not available - https://gist.github.com/jmshal/b14199f7402c8f3a4568733d8bed0f25
const atobPolyfill = (a: string) => Buffer.from(a, 'base64').toString('binary')
const atobPolyfill = (a: string) =>
typeof window === undefined ? Buffer.from(a, 'base64').toString('binary') : atob(a)

export const createImageUrl = (blob: string, type: string) =>
URL.createObjectURL(new Blob([fixBinary(atobPolyfill(blob))], { type }))

0 comments on commit 24cd918

Please sign in to comment.