{"id":16037273,"url":"https://github.com/stevenroose/rust-base64-compat","last_synced_at":"2025-08-01T11:11:27.162Z","repository":{"id":55075402,"uuid":"208055472","full_name":"stevenroose/rust-base64-compat","owner":"stevenroose","description":"base64 crate for Rust that supports rustc v0.19.0 and newer","archived":false,"fork":false,"pushed_at":"2021-01-12T17:37:10.000Z","size":343,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-16T16:51:24.699Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/stevenroose.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-09-12T13:17:22.000Z","updated_at":"2023-04-21T08:40:12.000Z","dependencies_parsed_at":"2022-08-14T11:20:13.248Z","dependency_job_id":null,"html_url":"https://github.com/stevenroose/rust-base64-compat","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenroose%2Frust-base64-compat","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenroose%2Frust-base64-compat/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenroose%2Frust-base64-compat/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stevenroose%2Frust-base64-compat/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stevenroose","download_url":"https://codeload.github.com/stevenroose/rust-base64-compat/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244156474,"owners_count":20407517,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-08T22:12:01.385Z","updated_at":"2025-03-18T04:30:37.061Z","avatar_url":"https://github.com/stevenroose.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"[base64-compat](https://crates.io/crates/base64-compat)\n===\n\n[![](https://img.shields.io/crates/v/base64-compat.svg)](https://crates.io/crates/base64-compat) [![Docs](https://docs.rs/base64-compat/badge.svg)](https://docs.rs/base64-compat) [![Build](https://travis-ci.org/stevenroose/rust-base64-compat.svg?branch=master)](https://travis-ci.org/stevenroose/rust-base64-compat) [![codecov](https://codecov.io/gh/stevenroose/rust-base64-compat/branch/master/graph/badge.svg)](https://codecov.io/gh/stevenroose/rust-base64-compat)\n\nIt's base64. What more could anyone want?\n\nPerhaps a stable API and compatibility with not-last-summer Rust versions?\n\nThis project is a fork of [rust-base64](https://github.com/marshallpierce/rust-base64/) with stable support for older Rust versions.\n\n\n----------\n\n\nThis 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_config_slice` decodes into an existing `\u0026mut [u8]` and is pretty fast (2.6GiB/s for a 3 KiB input), whereas `decode_config` allocates a new `Vec\u003cu8\u003e` and returns it, which might be more convenient in some cases, but is slower (although still fast enough for most purposes) at 2.1 GiB/s.\n\nExample\n---\n\nCargo.toml line: `base64-compat = \"1.0.0\"`\n\n```rust\nextern crate base64;\n\nuse base64::{encode, decode};\n\nfn main() {\n    let a = b\"hello world\";\n    let b = \"aGVsbG8gd29ybGQ=\";\n\n    assert_eq!(encode(a), b);\n    assert_eq!(a, \u0026decode(b).unwrap()[..]);\n}\n```\n\nSee the [docs](https://docs.rs/base64-compat) for all the details.\n\nRust version compatibility\n---\n\nThe minimum required Rust version is 1.19.0.\n\nDeveloping\n---\n\nBenchmarks are in `benches/`. Running them requires nightly rust, but `rustup` makes it easy:\n\n```bash\nrustup run nightly cargo bench\n```\n\nDecoding is aided by some pre-calculated tables, which are generated by:\n\n```bash\ncargo run --example make_tables \u003e src/tables.rs.tmp \u0026\u0026 mv src/tables.rs.tmp src/tables.rs\n```\n\nProfiling\n---\n\nOn 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`.\n\nRun the benchmark binary with `perf` (shown here filtering to one particular benchmark, which will make the results easier to read). `perf` is only available to the root user on most systems as it fiddles with event counters in your CPU, so use `sudo`. We need to run the actual benchmark binary, hence the path into `target`. You can see the actual full path with `rustup run nightly cargo bench -v`; it will print out the commands it runs. If you use the exact path that `bench` outputs, make sure you get the one that's for the benchmarks, not the tests. You may also want to `cargo clean` so you have only one `benchmarks-` binary (they tend to accumulate).\n\n```bash\nsudo perf record target/release/deps/benchmarks-* --bench decode_10mib_reuse\n```\n\nThen analyze the results, again with perf:\n\n```bash\nsudo perf annotate -l\n```\n\nYou'll see a bunch of interleaved rust source and assembly like this. The section with `lib.rs:327` is telling us that 4.02% of samples saw the `movzbl` aka bit shift as the active instruction. However, this percentage is not as exact as it seems due to a phenomenon called *skid*. Basically, a consequence of how fancy modern CPUs are is that this sort of instruction profiling is inherently inaccurate, especially in branch-heavy code.\n\n```text\n lib.rs:322    0.70 :     10698:       mov    %rdi,%rax\n    2.82 :        1069b:       shr    $0x38,%rax\n         :                  if morsel == decode_tables::INVALID_VALUE {\n         :                      bad_byte_index = input_index;\n         :                      break;\n         :                  };\n         :                  accum = (morsel as u64) \u003c\u003c 58;\n lib.rs:327    4.02 :     1069f:       movzbl (%r9,%rax,1),%r15d\n         :              // fast loop of 8 bytes at a time\n         :              while input_index \u003c length_of_full_chunks {\n         :                  let mut accum: u64;\n         :\n         :                  let input_chunk = BigEndian::read_u64(\u0026input_bytes[input_index..(input_index + 8)]);\n         :                  morsel = decode_table[(input_chunk \u003e\u003e 56) as usize];\n lib.rs:322    3.68 :     106a4:       cmp    $0xff,%r15\n         :                  if morsel == decode_tables::INVALID_VALUE {\n    0.00 :        106ab:       je     1090e \u003cbase64::decode_config_buf::hbf68a45fefa299c1+0x46e\u003e\n```\n\n\nFuzzing\n---\n\nThis 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:\n\n```bash\ncargo +nightly fuzz run roundtrip\ncargo +nightly fuzz run roundtrip_no_pad\ncargo +nightly fuzz run roundtrip_random_config -- -max_len=10240\ncargo +nightly fuzz run decode_random\n```\n\n\nLicense\n---\n\nThis project is a fork of the [rust-base64](https://github.com/marshallpierce/rust-base64/) project,\nwhich is dual-licensed under MIT and Apache 2.0.\nThis project is thus also dual-licensed under MIT and Apache 2.0.\n\nAll copyrights of code in this project belong to the original\ncopyright holders of the original rust-base64 project.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenroose%2Frust-base64-compat","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstevenroose%2Frust-base64-compat","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstevenroose%2Frust-base64-compat/lists"}