-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: use base64 encoding to speed up loading
- Loading branch information
1 parent
8824341
commit 118319b
Showing
3 changed files
with
26 additions
and
22 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,17 @@ | ||
use base64::{prelude::BASE64_STANDARD_NO_PAD, Engine}; | ||
|
||
pub(crate) fn create_load_inline_bytes_snippet(bytes: &[u8], variable_name: String) -> String { | ||
format!( | ||
" | ||
let {variable_name}; | ||
const base64 = \"{base64}\"; | ||
if (typeof Buffer === 'undefined') {{ | ||
{variable_name} = Uint8Array.from(atob(base64), c => c.charCodeAt(0)); | ||
}} else {{ | ||
{variable_name} = Buffer.from(base64, 'base64'); | ||
}} | ||
", | ||
variable_name = variable_name, | ||
base64 = BASE64_STANDARD_NO_PAD.encode(&bytes), | ||
) | ||
} |
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