Skip to content

Commit dfb572e

Browse files
committed
fix building in guest
1 parent 8c1f7d1 commit dfb572e

File tree

3 files changed

+44
-3
lines changed

3 files changed

+44
-3
lines changed

Cargo.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/codec/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,15 @@ bitvec.workspace = true
1919
derive_more = { version = "2.0", default-features = false }
2020
eyre = { workspace = true, optional = true }
2121
thiserror = { version = "2.0", default-features = false }
22-
zstd = "=0.13.3"
22+
zstd = { version = "=0.13.3", optional = true }
23+
ruzstd = { version = "0.8", optional = true }
2324

2425
[dev-dependencies]
2526
eyre.workspace = true
2627
serde_json = "1.0"
2728

2829
[features]
30+
default = ["zstd"]
2931
test-utils = ["dep:eyre", "scroll-l1/test-utils"]
32+
zstd = ["dep:zstd"]
33+
ruzstd = ["dep:ruzstd"]

crates/codec/src/decoding/v2/zstd.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,18 @@
22
33
use std::io::Read;
44

5-
use zstd::Decoder;
6-
75
/// The ZSTD magic number for zstd compressed data header.
86
const ZSTD_MAGIC_NUMBER: [u8; 4] = [0x28, 0xb5, 0x2f, 0xfd];
97

8+
#[cfg(not(any(feature = "zstd", feature = "ruzstd")))]
9+
compile_error!("Either feature \"zstd\" or \"ruzstd\" must be enabled for zstd support.");
10+
1011
/// Uncompress the provided data.
12+
#[cfg(feature = "zstd")]
1113
pub fn decompress_blob_data(data: &[u8]) -> Vec<u8> {
14+
use zstd::Decoder;
1215
let mut header_data = ZSTD_MAGIC_NUMBER.to_vec();
16+
1317
header_data.extend_from_slice(data);
1418

1519
// init decoder and owned output data.
@@ -31,3 +35,20 @@ pub fn decompress_blob_data(data: &[u8]) -> Vec<u8> {
3135

3236
output
3337
}
38+
39+
/// Uncompress the provided data.
40+
#[cfg(feature = "ruzstd")]
41+
pub fn decompress_blob_data(data: &[u8]) -> Vec<u8> {
42+
use ruzstd::decoding::StreamingDecoder;
43+
44+
let mut header_data = ZSTD_MAGIC_NUMBER.to_vec();
45+
header_data.extend_from_slice(data);
46+
47+
// init decoder and owned output data.
48+
let mut decoder = StreamingDecoder::new(header_data.as_slice()).unwrap();
49+
// heuristic: use data length as the allocated output capacity.
50+
let mut output = Vec::with_capacity(header_data.len());
51+
decoder.read_to_end(&mut output).unwrap();
52+
53+
output
54+
}

0 commit comments

Comments
 (0)