You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -11,8 +10,7 @@ It's base64. What more could anyone want?
11
10
12
11
This library's goals are to be *correct* and *fast*. It's thoroughly tested and widely used. It exposes functionality at multiple levels of abstraction so you can choose the level of convenience vs performance that you want, e.g. `decode_engine_slice` decodes into an existing `&mut [u8]` and is pretty fast (2.6GiB/s for a 3 KiB input), whereas `decode_engine` allocates a new `Vec<u8>` and returns it, which might be more convenient in some cases, but is slower (although still fast enough for almost any purpose) at 2.1 GiB/s.
13
12
14
-
Example
15
-
---
13
+
## Example
16
14
17
15
```rust
18
16
externcrate base64;
@@ -30,8 +28,24 @@ fn main() {
30
28
31
29
See the [docs](https://docs.rs/base64) for all the details.
32
30
33
-
Rust version compatibility
34
-
---
31
+
## FAQ
32
+
33
+
### I need to decode base64 with whitespace/null bytes/other random things interspersed in it. What should I do?
34
+
35
+
Remove non-base64 characters from your input before decoding.
36
+
37
+
If you have a `Vec` of base64, [retain](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain) can be used to strip out whatever you need removed.
38
+
39
+
If you have a `Read` (e.g. reading a file or network socket), there are various approaches.
40
+
41
+
- Use [iter_read](https://crates.io/crates/iter-read) together with `Read`'s `bytes()` to filter out unwanted bytes.
42
+
- Implement `Read` with a `read()` impl that delegates to your actual `Read`, and then drops any bytes you don't want.
43
+
44
+
### I need to line-wrap base64, e.g. for MIME/PEM.
45
+
46
+
[line-wrap](https://crates.io/crates/line-wrap) does just that.
47
+
48
+
## Rust version compatibility
35
49
36
50
The minimum required Rust version is 1.47.0.
37
51
@@ -41,22 +55,19 @@ Contributions are very welcome. However, because this library is used widely, an
41
55
42
56
All this means that it takes me a fair amount of time to review each PR, so it might take quite a while to carve out the free time to give each PR the attention it deserves. I will get to everyone eventually!
43
57
44
-
Developing
45
-
---
58
+
## Developing
46
59
47
60
Benchmarks are in `benches/`. Running them requires nightly rust, but `rustup` makes it easy:
48
61
49
62
```bash
50
63
rustup run nightly cargo bench
51
64
```
52
65
53
-
no_std
54
-
---
66
+
## no_std
55
67
56
68
This crate supports no_std. By default the crate targets std via the `std` feature. You can deactivate the `default-features` to target core instead. In that case you lose out on all the functionality revolving around `std::io`, `std::error::Error` and heap allocations. There is an additional `alloc` feature that you can activate to bring back the support for heap allocations.
57
69
58
-
Profiling
59
-
---
70
+
## Profiling
60
71
61
72
On Linux, you can use [perf](https://perf.wiki.kernel.org/index.php/Main_Page) for profiling. Then compile the benchmarks with `rustup nightly run cargo bench --no-run`.
62
73
@@ -95,8 +106,7 @@ You'll see a bunch of interleaved rust source and assembly like this. The sectio
95
106
```
96
107
97
108
98
-
Fuzzing
99
-
---
109
+
## Fuzzing
100
110
101
111
This uses [cargo-fuzz](https://github.com/rust-fuzz/cargo-fuzz). See `fuzz/fuzzers` for the available fuzzing scripts. To run, use an invocation like these:
102
112
@@ -108,7 +118,6 @@ cargo +nightly fuzz run decode_random
108
118
```
109
119
110
120
111
-
License
112
-
---
121
+
## License
113
122
114
123
This project is dual-licensed under MIT and Apache 2.0.
0 commit comments