Skip to content

Commit

Permalink
fromBase64 not yet implemented as standard
Browse files Browse the repository at this point in the history
  • Loading branch information
cmdcolin committed Dec 12, 2024
1 parent a5785e1 commit 1d80609
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@gmod/abortable-promise-cache": "^2.0.0",
"@gmod/bgzf-filehandle": "^2.0.1",
"crc": "^4.3.2",
"generic-filehandle2": "^0.0.2",
"generic-filehandle2": "^1.0.0",
"long": "^4.0.0",
"quick-lru": "^4.0.0"
},
Expand Down
10 changes: 8 additions & 2 deletions src/htsget.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,14 @@ async function concat(arr: HtsgetChunk[], opts?: Record<string, any>) {
arr.map(async chunk => {
const { url, headers } = chunk
if (url.startsWith('data:')) {
// @ts-expect-error
return Uint8Array.fromBase64(url.split(',')[1], 'base64') as Uint8Array
// pass base64 data url to fetch to decode to buffer
// https://stackoverflow.com/a/54123275/2129219
const res = await fetch(url)
if (!res.ok) {
throw new Error('failed to decode base64')
}
const ret = await res.arrayBuffer()
return new Uint8Array(ret)
} else {
//remove referer header, it is not even allowed to be specified
// @ts-expect-error
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,11 @@ generic-filehandle2@^0.0.2:
resolved "https://registry.yarnpkg.com/generic-filehandle2/-/generic-filehandle2-0.0.2.tgz#a87839bdefa5cebb8aec6aa1486f904595908dde"
integrity sha512-8v2ZOMiJ2uneKpaKNqCTFDBmXai4nihRd8QY9G6vQ9JRcuaDrkwSKxlGM4A0k2X4XNr+X02T6RMv1QPT9fgPEw==

generic-filehandle2@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/generic-filehandle2/-/generic-filehandle2-1.0.0.tgz#d7a216072467793e1e48c925f97162eab1b82efc"
integrity sha512-jXfyNk1zhsR0Xf2sLm4vgeYSP1q1XbeSVG0TRSnOCKLb2CojPNJyy57nKi6QWmt83yGSHZGay8qIn7YWyl2V5w==

git-raw-commits@^5.0.0:
version "5.0.0"
resolved "https://registry.yarnpkg.com/git-raw-commits/-/git-raw-commits-5.0.0.tgz#38af4301e70c17be03fec01a37a6cd90ce0db04e"
Expand Down

0 comments on commit 1d80609

Please sign in to comment.