Skip to content

Commit

Permalink
Merge pull request #148 from kpcyrd/base64
Browse files Browse the repository at this point in the history
Replace base64 crate with data-encoding
  • Loading branch information
kpcyrd authored Nov 11, 2024
2 parents a1c706c + 7b6c1af commit e024e74
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 16 deletions.
8 changes: 1 addition & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tools/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ regex = "1.5.6"
url = "2.2.2"

[dev-dependencies]
base64 = "0.13.0"
data-encoding = "2"
17 changes: 9 additions & 8 deletions tools/src/decompress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ pub fn stream<'a>(comp: CompressedWith, bytes: &'a [u8]) -> Result<Box<dyn Read
#[cfg(test)]
mod tests {
use super::*;
use data_encoding::BASE64;

#[test]
fn detect_no_compression() {
Expand All @@ -62,14 +63,14 @@ mod tests {

#[test]
fn detect_gzip_compression() {
let bytes = base64::decode("H4sIAAAAAAAAA8vPSMzkAgCKUC0+BQAAAA==").unwrap();
let bytes = BASE64.decode(b"H4sIAAAAAAAAA8vPSMzkAgCKUC0+BQAAAA==").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Gzip);
}

#[test]
fn decompress_gzip_compression() {
let bytes = base64::decode("H4sIAAAAAAAAA8vPSMzkAgCKUC0+BQAAAA==").unwrap();
let bytes = BASE64.decode(b"H4sIAAAAAAAAA8vPSMzkAgCKUC0+BQAAAA==").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Gzip);

Expand All @@ -80,14 +81,14 @@ mod tests {

#[test]
fn detect_bzip2_compression() {
let bytes = base64::decode("QlpoOTFBWSZTWZ+CN7sAAAJBAAAQIGCgADDNAMGmwHF3JFOFCQn4I3uw").unwrap();
let bytes = BASE64.decode(b"QlpoOTFBWSZTWZ+CN7sAAAJBAAAQIGCgADDNAMGmwHF3JFOFCQn4I3uw").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Bzip2);
}

#[test]
fn decompress_bzip2_compression() {
let bytes = base64::decode("QlpoOTFBWSZTWZ+CN7sAAAJBAAAQIGCgADDNAMGmwHF3JFOFCQn4I3uw").unwrap();
let bytes = BASE64.decode(b"QlpoOTFBWSZTWZ+CN7sAAAJBAAAQIGCgADDNAMGmwHF3JFOFCQn4I3uw").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Bzip2);

Expand All @@ -98,14 +99,14 @@ mod tests {

#[test]
fn detect_xz_compression() {
let bytes = base64::decode("/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAQAEb2hhaQoAAAAACyuekVbXbHMAAR0FuC2Arx+2830BAAAAAARZWg==").unwrap();
let bytes = BASE64.decode(b"/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAQAEb2hhaQoAAAAACyuekVbXbHMAAR0FuC2Arx+2830BAAAAAARZWg==").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Xz);
}

#[test]
fn decompress_xz_compression() {
let bytes = base64::decode("/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAQAEb2hhaQoAAAAACyuekVbXbHMAAR0FuC2Arx+2830BAAAAAARZWg==").unwrap();
let bytes = BASE64.decode(b"/Td6WFoAAATm1rRGAgAhARYAAAB0L+WjAQAEb2hhaQoAAAAACyuekVbXbHMAAR0FuC2Arx+2830BAAAAAARZWg==").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Xz);

Expand All @@ -116,14 +117,14 @@ mod tests {

#[test]
fn detect_zstd_compression() {
let bytes = base64::decode("KLUv/QRYKQAAb2hhaQpnBE++").unwrap();
let bytes = BASE64.decode(b"KLUv/QRYKQAAb2hhaQpnBE++").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Zstd);
}

#[test]
fn decompress_zstd_compression() {
let bytes = base64::decode("KLUv/QRYKQAAb2hhaQpnBE++").unwrap();
let bytes = BASE64.decode(b"KLUv/QRYKQAAb2hhaQpnBE++").unwrap();
let comp = detect_compression(&bytes);
assert_eq!(comp, CompressedWith::Zstd);

Expand Down

0 comments on commit e024e74

Please sign in to comment.