Skip to content

Commit

Permalink
fix: esm-modules break because Buffer is not available (#287)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaellis authored Feb 3, 2021
1 parent ad42f1f commit e6d3a5c
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 e6d3a5c

Please sign in to comment.