-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: properly decode base64 strings inside
read
(#11682)
* fix: properly decode base64 strings inside `read` * test --------- Co-authored-by: Rich Harris <rich.harris@vercel.com>
- Loading branch information
1 parent
e228f89
commit 5dae367
Showing
8 changed files
with
59 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@sveltejs/kit': patch | ||
--- | ||
|
||
fix: properly decode base64 strings inside `read` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/** | ||
* @param {string} text | ||
* @returns {ArrayBufferLike} | ||
*/ | ||
export function b64_decode(text) { | ||
const d = atob(text); | ||
|
||
const u8 = new Uint8Array(d.length); | ||
|
||
for (let i = 0; i < d.length; i++) { | ||
u8[i] = d.charCodeAt(i); | ||
} | ||
|
||
return u8.buffer; | ||
} | ||
|
||
/** | ||
* @param {ArrayBuffer} buffer | ||
* @returns {string} | ||
*/ | ||
export function b64_encode(buffer) { | ||
if (globalThis.Buffer) { | ||
return Buffer.from(buffer).toString('base64'); | ||
} | ||
|
||
const little_endian = new Uint8Array(new Uint16Array([1]).buffer)[0] > 0; | ||
|
||
// The Uint16Array(Uint8Array(...)) ensures the code points are padded with 0's | ||
return btoa( | ||
new TextDecoder(little_endian ? 'utf-16le' : 'utf-16be').decode( | ||
new Uint16Array(new Uint8Array(buffer)) | ||
) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Imported without ?url | ||
Imported without ?url π |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Imported with ?url | ||
Imported with ?url π |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters