Skip to content

Added legacy shrink/reduce/implode compression. #303

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

mkrueger
Copy link

@mkrueger mkrueger commented Mar 4, 2025

Replaces #120

The original PR grew too large to sanely merge it - ported it manually to zip-rs HEAD and reopened the PR.

I need the legacy formats for my BBS project which I've not touched for some while but I've continued on that lately.

Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good; just some nitpicks.

@mkrueger mkrueger requested a review from Pr0methean March 17, 2025 08:51
@mkrueger
Copy link
Author

ty

@Pr0methean Pr0methean enabled auto-merge March 17, 2025 12:39
Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests are failing because a new dependency requires Rust 1.79. You can increase the MSRV for zip to 1.79 to fix this, or replace the dependency if that's somehow easier.

@Pr0methean Pr0methean added the Please fix failing tests Tests are failing with this change; please fix them. label Mar 17, 2025
auto-merge was automatically disabled March 24, 2025 04:39

Head branch was pushed to by a user without write access

@mkrueger mkrueger force-pushed the legacy-zip2 branch 2 times, most recently from 1125d37 to eaeccf6 Compare March 24, 2025 04:40
@mkrueger
Copy link
Author

Updated to bitstream-io 2.6.0 + upped rust version.

Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good, but still a fair number of nitpicks.

///
/// # Returns
///
/// * `Ok(())` if the byte was successfully read.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// * `Ok(())` if the byte was successfully read.
/// * `Ok` with the byte if it was successfully read.


struct CodeQueue {
next_idx: usize,
codes: [Option<u16>; MAX_CODE - CONTROL_CODE + 1]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Factor out a constant for MAX_CODE - CONTROL_CODE + 1 (maybe called CODE_ARRAY_LEN).

impl CodeQueue {
fn new() -> Self {
let mut codes = [None; MAX_CODE as usize - CONTROL_CODE + 1];
for (i, code) in (CONTROL_CODE as u16 + 1..=MAX_CODE as u16).enumerate() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need clarifying parentheses here as well.

}

impl Codetab {
pub fn create_new() -> [Self; MAX_CODE + 1] {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create a slice [Codetab::default(); MAX_CODE + 1] and just overwrite the first 0..=u8::MAX entries. This will probably be more efficient because it eliminates the heap allocation and reallocation.

@@ -10,7 +10,7 @@ authors = [
license = "MIT"
repository = "https://github.com/zip-rs/zip2.git"
keywords = ["zip", "archive", "compression"]
rust-version = "1.73.0"
rust-version = "1.83.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is version 1.83.0 needed? I won't release this change until the MSRV has been stable for 6 months; for 1.83.0 that would mean 2025-05-28.

Also, an MSRV change needs to be reflected in README.md and .github/workflows/ci.yaml; the latter is why CI is failing for this PR.

let mut is_prefix = [false; MAX_CODE + 1];

// Scan for codes that have been used as a prefix.
for i in CONTROL_CODE + 1..=MAX_CODE {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need clarifying parentheses.

}

/// Read the next code from the input stream and return it in next_code. Returns
/// false if the end of the stream is reached. If the stream contains invalid
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// false if the end of the stream is reached. If the stream contains invalid
/// `Ok(None)` if the end of the stream is reached. If the stream contains invalid


/// Read the next code from the input stream and return it in next_code. Returns
/// false if the end of the stream is reached. If the stream contains invalid
/// data, next_code is set to INVALID_CODE but the return value is still true.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// data, next_code is set to INVALID_CODE but the return value is still true.
/// data, returns `Err`.

let mut code_size = MIN_CODE_SIZE;

// Handle the first code separately since there is no previous code.
let Ok(Some(curr_code)) = read_code(&mut is, &mut code_size, &mut codetab, &mut queue) else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this pass through any error it receives? (Use the ? operator to do that.)

@@ -0,0 +1,2 @@
#67h���<D��������P!T�oՖK�Ѻt˺[V�Y�E��}��[� ��m˶,]� ��y5-[�i�7ȩhî-;nٰr���Mmڹ ˼7�7�V.H�h˂�;��� �6�[�e�����·��^�m�tM&Y�c��t?c�������o8ٚ���>�@k6��|�t����~���A�l����_�
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Git still thinks this is a text file.

Copy link
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See my previous review; GitHub didn't think it was finished for some reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Please fix failing tests Tests are failing with this change; please fix them.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants