Crates.io | base64s |
lib.rs | base64s |
version | 0.1.0 |
source | src |
created_at | 2019-08-22 00:47:22.418794 |
updated_at | 2019-08-22 00:47:22.418794 |
description | Base64s base on RFC4648 基于 RFC4648 文档编写的 Base64 编码解码库 |
homepage | |
repository | |
max_upload_size | |
id | 158772 |
size | 1,106,328 |
Rust-lang: The base64s crate base on RFC4648
base64s 库是基于规范文档 RFC4648 编写的库
This crate is very simple
这个库非常简单易用
Usually, we use encode () and decode (). But if Base64 is used for URLs, encode_url() and decode_url() should be used.
通常情况下,我们会用到 encode() 和 decode()。但如果 Base64 被用于 URL,那么就应该使用 encode_url() 和 decode_url()
encode
Given a string, return an encode result. This is the inverse of decode().
decode
Given a String, return a decode result, it's original of encode(). This is the inverse of decode().
encode_url
Like encode(), this is for url.
decode_url
Like decode(), this is for url
&str to String, "Bruce Done say: Hi,I'm frank。" -> "QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua+OAgg=="
Example
use bases64s::bases::Bases;
let bases = Bases{};
let res = bases.encode("Bruce Done say: Hi,I'm frank。");
assert_eq!(res, String::from("QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua+OAgg=="));
String to String, "QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua+OAgg==" -> "Bruce Done say: Hi,I'm frank。"
Example
use bases64s::bases::Bases;
let bases = Bases{};
let res = bases.decode(String::from("QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua+OAgg=="));
assert_eq!(res, String::from("Bruce Done say: Hi,I'm frank。"));
For url.
&str to String, "Bruce Done say: Hi,I'm frank。" -> "QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua-OAgg=="
Example
use bases64s::bases::Bases;
let bases = Bases{};
let res = bases.encode_url("Bruce Done say: Hi,I'm frank。");
assert_eq!(res, String::from("QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua-OAgg=="));
For url.
Example
use bases64s::bases::Bases;
let bases = Bases{};
let res = bases.decode_url(String::from("QnJ1Y2UgRG9uZSBzYXk6IEhpLEknbSBmcmFua-OAgg=="));
assert_eq!(res, String::from("Bruce Done say: Hi,I'm frank。"));