Skip to content

Commit

Permalink
feat(http): enhance base64ToArrayBuffer()
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Oct 15, 2022
1 parent 9e002d7 commit fc74832
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/axios/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,16 @@ declare module 'cordis' {
}

export function base64ToArrayBuffer(base64: string) {
const binary = atob(base64)
const result = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) {
result[i] = binary.charCodeAt(i)
if (typeof Buffer !== 'undefined') {
return Buffer.from(base64, 'base64').buffer
} else {
const binary = atob(base64.replace(/\s/g, ''))
const buffer = new Uint8Array(binary.length)
for (let i = 0; i < binary.length; i++) {
buffer[i] = binary.charCodeAt(i)
}
return buffer
}
return result
}

export interface Quester {
Expand Down

0 comments on commit fc74832

Please sign in to comment.