Skip to content
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

Properly compress files which are already partially compressed #54

Closed
marcospb19 opened this issue Sep 27, 2021 · 2 comments · Fixed by #91
Closed

Properly compress files which are already partially compressed #54

marcospb19 opened this issue Sep 27, 2021 · 2 comments · Fixed by #91
Labels
enhancement New feature or request good first issue Good for newcomers high priority
Milestone

Comments

@marcospb19
Copy link
Member

There is currently no way to compress an file.tar into file.tar.gz by only adding the .gz part, ouch will detect two extensions, tar and gz, repeating the .tar process for that file that was already in that format.

So basically, ouch compress file.tar.gz file.tar.gz.xz generates a file of format .tar.gz.tar.gz.xz, instead of .tar.gz.xz.

@marcospb19
Copy link
Member Author

marcospb19 commented Sep 27, 2021

I have already thought about a solution for this, here is some pseudocode:

Assume ouch was called like this:

ouch compress file.tar.gz file.tar.gz.xz

We correctly check if it's compressing only one file, as this check additional check does not make sense when creating archives.

Then we can run the function to detect the extensions of both files.

input : [Tar, Gz]
output: [Tar, Gz, Xz]

Now we check if the input extensions are a sublist of the output extensions (and at the start).

let input_extensions_are_included_in_output_extensions =
    input_extensions.len() < output_extensions.len()
        && input_extensions.iter().zip(&output_extensions).all(|(a, b)| a == b);

In this case, instead of passing the output_extensions normally to the compress function, we drop the first N elements.

// Remove the first N elements efficiently
let drain_iter = output_extensions.drain(..input_extensions.len());
drop(drain_iter); // [Tar, Gz, Xz] -> [Xz]

Now use the output_extensions and only compress file with the remaning Xz.

@marcospb19 marcospb19 changed the title Add compression format on top of files that are already compressed Properly compress files which are already compressed Oct 1, 2021
@marcospb19 marcospb19 added enhancement New feature or request high priority good first issue Good for newcomers labels Oct 3, 2021
@marcospb19 marcospb19 changed the title Properly compress files which are already compressed Properly compress files which are already partially compressed Oct 7, 2021
@marcospb19
Copy link
Member Author

Note: this should not care if the filenames are different.

file.tar -> output.tar.gz still should skip the .tar compression part.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers high priority
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant