mirror of
https://github.com/ente-io/ente.git
synced 2025-08-08 07:28:26 +00:00
The other way
This commit is contained in:
parent
b49e829cc5
commit
485614166d
@ -398,16 +398,35 @@ export async function toB64(input: Uint8Array) {
|
||||
return sodium.to_base64(input, sodium.base64_variants.ORIGINAL);
|
||||
}
|
||||
|
||||
/** Convert a {@link Uint8Array} to a URL safe Base64 encoded string. */
|
||||
export const toB64URLSafe = async (input: Uint8Array) => {
|
||||
await sodium.ready;
|
||||
return sodium.to_base64(input, sodium.base64_variants.URLSAFE);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a {@link Uint8Array} to a URL safe Base64 encoded string.
|
||||
*
|
||||
* This differs from {@link toB64URLSafe} in that it does not append any
|
||||
* trailing padding character(s) "=" to make the resultant string's length be an
|
||||
* integer multiple of 4.
|
||||
*/
|
||||
export const toB64URLSafeNoPadding = async (input: Uint8Array) => {
|
||||
await sodium.ready;
|
||||
return sodium.to_base64(input, sodium.base64_variants.URLSAFE_NO_PADDING);
|
||||
};
|
||||
|
||||
/**
|
||||
* Convert a Base64 encoded string to a {@link Uint8Array}.
|
||||
*
|
||||
* This is the converse of {@link toB64URLSafeNoPadding}, and does not expect
|
||||
* its input string's length to be a an integer multiple of 4.
|
||||
*/
|
||||
export const fromB64URLSafeNoPadding = async (input: string) => {
|
||||
await sodium.ready;
|
||||
return sodium.from_base64(input, sodium.base64_variants.URLSAFE_NO_PADDING);
|
||||
};
|
||||
|
||||
export async function fromUTF8(input: string) {
|
||||
await sodium.ready;
|
||||
return sodium.from_string(input);
|
||||
|
Loading…
x
Reference in New Issue
Block a user