Skip to content

Commit

Permalink
Add ZSTD support to Rust library (google#84)
Browse files Browse the repository at this point in the history
  • Loading branch information
kralka authored Jan 7, 2025
1 parent bef502e commit 0261b66
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 0 deletions.
1 change: 1 addition & 0 deletions project-words.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,4 @@ tfrecord
tfrecords
tobytes
uoffset
zstd
46 changes: 46 additions & 0 deletions rust/Cargo.lock

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

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@ rand = "0.8"
strum = "0.26.3"
strum_macros = "0.26.4"
yoke = { version = "0.7", features = ["derive"] }
zstd = "0.13.2"
4 changes: 4 additions & 0 deletions rust/src/example_iteration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ pub enum CompressionType {
LZ4,
Gzip,
Zlib,
Zstd,
}

impl CompressionType {
Expand All @@ -48,6 +49,7 @@ impl std::fmt::Display for CompressionType {
CompressionType::LZ4 => write!(f, "LZ4"),
CompressionType::Gzip => write!(f, "GZIP"),
CompressionType::Zlib => write!(f, "ZLIB"),
CompressionType::Zstd => write!(f, "ZSTD"),
}
}
}
Expand All @@ -61,6 +63,7 @@ impl std::str::FromStr for CompressionType {
"LZ4" => Ok(CompressionType::LZ4),
"GZIP" => Ok(CompressionType::Gzip),
"ZLIB" => Ok(CompressionType::Zlib),
"ZSTD" => Ok(CompressionType::Zstd),
_ => Err(format!("{input} unimplemented")),
}
}
Expand Down Expand Up @@ -128,6 +131,7 @@ fn get_file_bytes(shard_info: &ShardInfo) -> Vec<u8> {
CompressionType::Gzip | CompressionType::Zlib => {
read_to_end(flate2::read::GzDecoder::new(open_file))
}
CompressionType::Zstd => zstd::stream::decode_all(open_file).unwrap(),
}
}

Expand Down

0 comments on commit 0261b66

Please sign in to comment.