Crates.io | win-base64 |
lib.rs | win-base64 |
version | 0.1.2 |
source | src |
created_at | 2022-01-16 12:25:03.611033 |
updated_at | 2022-01-16 13:40:34.587022 |
description | Windows API Base64 Wrapper |
homepage | https://github.com/pratikpc/rust-win-base64 |
repository | https://github.com/pratikpc/rust-win-base64 |
max_upload_size | |
id | 514822 |
size | 12,785 |
A simple wrapper over the Windows API Base64 Encoding and Decoding
encode
)decode
)use win_base64::decode;
use win_base64::encode;
let text = "What's up?😊🥘🍲🚩🏁🚀👌😁👍😍❤️💕🎶";
let base64_string = encode(&text)?;
let decoded_text = decode(&base64_string)?;
// If it worked, text and decoded_text would be the same
println!("Original: {}", text);
println!("Decoded : {}", decoded_text);
Original: What's up?😊👌😁👍😍❤️💕🎶
Decoded: What's up?😊👌😁👍😍❤️💕🎶
Yes this supports Emojis.
let a = "hello world";
let b = "aGVsbG8gd29ybGQ=";
assert_eq!(encode(a)?, b);
assert_eq!(a, &decode(b)?[..]);
Decode as &mut [u8]
(decode_as_mut8
)
Probably the fastest
But the sizes are to be specified manually.
So probably the riskiest as well.
let text = "What's up?";
let base64_string = encode(&text)?;
let mut decoded_arr = vec![0u8; 10];
use win_base64::decode_as_mut8;
decode_as_mut8(&base64_string, &mut decoded_arr)?;
// If it worked, text and decoded_text would be the same
println!("Original: {}", text);
println!("Decoded : {:?}", decoded_arr);
Decode as Vec<u8>
(decode_as_vecu8
)
Allocates a vec of the correct size
Returns this vec with decoded values
Safer than mut u8 as it knows the decoded size
let text = "What's up?";
let base64_string = encode(&text)?;
use win_base64::decode_as_vecu8;
let decoded_vec = decode_as_vecu8(&base64_string)?;
// If it worked, text and decoded_text would be the same
println!("Original: {}", text);
println!("Decoded : {:?}", decoded_vec);
Decode as String (decode
)
Present in top most example
use win_base64::decode;
use win_base64::encode;
let text = "What's up?😊🥘🍲🚩🏁🚀👌😁👍😍❤️💕🎶";
let base64_string = encode(&text)?;
let decoded_text = decode(&base64_string)?;
// If it worked, text and decoded_text would be the same
println!("Original: {}", text);
println!("Decoded : {}", decoded_text);