Skip to content

Commit dd0e5ca

Browse files
Add FAQ
1 parent 6438a16 commit dd0e5ca

File tree

1 file changed

+25
-16
lines changed

1 file changed

+25
-16
lines changed

README.md

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
[base64](https://crates.io/crates/base64)
2-
===
1+
# [base64](https://crates.io/crates/base64)
32

43
[![](https://img.shields.io/crates/v/base64.svg)](https://crates.io/crates/base64) [![Docs](https://docs.rs/base64/badge.svg)](https://docs.rs/base64) [![CircleCI](https://circleci.com/gh/marshallpierce/rust-base64/tree/master.svg?style=shield)](https://circleci.com/gh/marshallpierce/rust-base64/tree/master) [![codecov](https://codecov.io/gh/marshallpierce/rust-base64/branch/master/graph/badge.svg)](https://codecov.io/gh/marshallpierce/rust-base64) [![unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg)](https://github.com/rust-secure-code/safety-dance/)
54

@@ -11,8 +10,7 @@ It's base64. What more could anyone want?
1110

1211
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.
1312

14-
Example
15-
---
13+
## Example
1614

1715
```rust
1816
extern crate base64;
@@ -30,8 +28,24 @@ fn main() {
3028

3129
See the [docs](https://docs.rs/base64) for all the details.
3230

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
3549

3650
The minimum required Rust version is 1.47.0.
3751

@@ -41,22 +55,19 @@ Contributions are very welcome. However, because this library is used widely, an
4155

4256
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!
4357

44-
Developing
45-
---
58+
## Developing
4659

4760
Benchmarks are in `benches/`. Running them requires nightly rust, but `rustup` makes it easy:
4861

4962
```bash
5063
rustup run nightly cargo bench
5164
```
5265

53-
no_std
54-
---
66+
## no_std
5567

5668
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.
5769

58-
Profiling
59-
---
70+
## Profiling
6071

6172
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`.
6273

@@ -95,8 +106,7 @@ You'll see a bunch of interleaved rust source and assembly like this. The sectio
95106
```
96107

97108

98-
Fuzzing
99-
---
109+
## Fuzzing
100110

101111
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:
102112

@@ -108,7 +118,6 @@ cargo +nightly fuzz run decode_random
108118
```
109119

110120

111-
License
112-
---
121+
## License
113122

114123
This project is dual-licensed under MIT and Apache 2.0.

0 commit comments

Comments
 (0)