-
Notifications
You must be signed in to change notification settings - Fork 82
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Enable customizing Zstd decoding parameters. #285
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
#![cfg(not(windows))] | ||
|
||
use async_compression::zstd::DParameter; | ||
use tokio::io::AsyncWriteExt as _; | ||
|
||
#[tokio::test] | ||
async fn zstd_decode_large_window_size_default() { | ||
let compressed = include_bytes!("./artifacts/long-window-size-lib.rs.zst"); | ||
|
||
// Default decoder should throw with an error, window size maximum is too low. | ||
let mut decoder = async_compression::tokio::write::ZstdDecoder::new(Vec::new()); | ||
decoder.write_all(compressed).await.unwrap_err(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn zstd_decode_large_window_size_explicit_small_window_size() { | ||
let compressed = include_bytes!("./artifacts/long-window-size-lib.rs.zst"); | ||
|
||
// Short window decoder should throw with an error, window size maximum is too low. | ||
let mut decoder = async_compression::tokio::write::ZstdDecoder::with_params( | ||
Vec::new(), | ||
&[DParameter::window_log_max(16)], | ||
); | ||
decoder.write_all(compressed).await.unwrap_err(); | ||
} | ||
|
||
#[tokio::test] | ||
async fn zstd_decode_large_window_size_explicit_large_window_size() { | ||
let compressed = include_bytes!("./artifacts/long-window-size-lib.rs.zst"); | ||
let source = include_bytes!("./artifacts/lib.rs"); | ||
|
||
// Long window decoder should succeed as the window size is large enough to decompress the given input. | ||
let mut long_window_size_decoder = async_compression::tokio::write::ZstdDecoder::with_params( | ||
Vec::new(), | ||
&[DParameter::window_log_max(31)], | ||
); | ||
// Long window size decoder should successfully decode the given input data. | ||
long_window_size_decoder | ||
.write_all(compressed) | ||
.await | ||
.unwrap(); | ||
long_window_size_decoder.shutdown().await.unwrap(); | ||
|
||
assert_eq!(long_window_size_decoder.into_inner(), source); | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should propagate the error from zstd?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not necessarily opposed to this, though in the interest of consistency, it appears that this library chooses to panic on construction errors for other encoders/decoders:
async-compression/src/codec/zstd/encoder.rs
Line 18 in 7c2d530
async-compression/src/codec/xz2/encoder.rs
Line 23 in 7c2d530
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's unfortunate, maybe we should add a
try_
variant for these APIs?cc @robjtede what's your thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think typically panics are acceptable when it comes to "programmer error" and I really, really don't expect decoding parameters to be user-input, or anything other than hardcoded. Therefore it's fine to me that this can panic. It's a fairly unrecoverable error for both these unwraps.