planetscale / planetscale/database-js
base64 compatibility
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.2k
- Forks
- 42
- PR merge metrics
- No merged PRs in 30d
Description
We currently rely on btoa and atob, because that works in browsers and worked in versions of Node we tested against, but that's not as universal as we had hoped.
We should instead, provide some compatibility shim against the Buffer API that should more likely exist? We might need to provide a fallback for even that if neither Buffer nor btoa and friends exist.
But for now, it seems either way, it'd be more favorable to use the Buffer API when available over btoa.
I propose something like this, granted I dunno the best way to do this in JavaScript/TypeScript these days:
var b64encode;
var b64decode;
if(typeof Buffer !== "undefined") {
b64encode = x => Buffer.from(x, 'latin1').toString('base64')
b64decode = x => Buffer.from(x, 'base64').toString('latin1')
} else if (typeof btoa !== "undefined") {
b64encode = btoa
b64decode = atob
} else {
// I dunno, natively has neither
}
console.log(b64encode('foo'))
console.log(b64decode('Zm9v'))
I think this is still reasonably applicable since we don't simply use it for the Authorization header. While that's the only use of btoa, atob is used to decode binary row data, which we do for every row in a QueryResult.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
No file or test is named. Start by locating the btoa and atob calls in the TypeScript driver, then inspect how binary row data and authorization encoding are handled across supported runtimes. Done means Buffer is preferred when available, browser APIs remain supported, and the behavior is covered for environments lacking one of those APIs.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js, typescript
- Domain
- database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100