-
-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
188 additions
and
133 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 |
---|---|---|
@@ -1,47 +1,21 @@ | ||
import gleam/bit_array | ||
import gleam/string | ||
|
||
/// Encodes a BitArray into a base 64 encoded string. | ||
/// | ||
@deprecated("Please use `base64_encode` in the `gleam/bit_array` module instead.") | ||
pub fn encode64(input: BitArray, padding: Bool) -> String { | ||
let encoded = do_encode64(input) | ||
case padding { | ||
True -> encoded | ||
False -> string.replace(encoded, "=", "") | ||
} | ||
bit_array.base64_encode(input, padding) | ||
} | ||
|
||
@external(erlang, "base64", "encode") | ||
@external(javascript, "../gleam_stdlib.mjs", "encode64") | ||
fn do_encode64(a: BitArray) -> String | ||
|
||
/// Decodes a base 64 encoded string into a `BitArray`. | ||
/// | ||
@deprecated("Please use `base64_decode` in the `gleam/bit_array` module instead.") | ||
pub fn decode64(encoded: String) -> Result(BitArray, Nil) { | ||
let padded = case bit_array.byte_size(bit_array.from_string(encoded)) % 4 { | ||
0 -> encoded | ||
n -> string.append(encoded, string.repeat("=", 4 - n)) | ||
} | ||
do_decode64(padded) | ||
bit_array.base64_decode(encoded) | ||
} | ||
|
||
@external(erlang, "gleam_stdlib", "base_decode64") | ||
@external(javascript, "../gleam_stdlib.mjs", "decode64") | ||
fn do_decode64(a: String) -> Result(BitArray, Nil) | ||
|
||
/// Encodes a `BitArray` into a base 64 encoded string with URL and filename safe alphabet. | ||
/// | ||
@deprecated("Please use `base64_url_encode` in the `gleam/bit_array` module instead.") | ||
pub fn url_encode64(input: BitArray, padding: Bool) -> String { | ||
encode64(input, padding) | ||
|> string.replace("+", "-") | ||
|> string.replace("/", "_") | ||
bit_array.base64_url_encode(input, padding) | ||
} | ||
|
||
/// Decodes a base 64 encoded string with URL and filename safe alphabet into a `BitArray`. | ||
/// | ||
@deprecated("Please use `base64_url_decode` in the `gleam/bit_array` module instead.") | ||
pub fn url_decode64(encoded: String) -> Result(BitArray, Nil) { | ||
encoded | ||
|> string.replace("-", "+") | ||
|> string.replace("_", "/") | ||
|> decode64() | ||
bit_array.base64_url_decode(encoded) | ||
} |
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
Oops, something went wrong.