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

Add lzip support #401

Merged
merged 2 commits into from Apr 8, 2024
Merged

Add lzip support #401

merged 2 commits into from Apr 8, 2024

Conversation

sorairolake
Copy link
Contributor

Closes #400

@sorairolake sorairolake force-pushed the add-lzip-support branch 2 times, most recently from e939b4f to 395e228 Compare April 7, 2024 12:02
@mholt
Copy link
Owner

mholt commented Apr 8, 2024

Nice, thank you! This is looking good. Will merge this shortly. Appreciate your contribution!

@mholt
Copy link
Owner

mholt commented Apr 8, 2024

Hm, lz4 compression with extension is failing. @sorairolake Does it fail for you locally?

@sorairolake
Copy link
Contributor Author

sorairolake commented Apr 8, 2024

@mholt Just now, I ran the test locally 10 times, 8 passed but 2 failed. I don't know why the test sometimes fails.

@mholt
Copy link
Owner

mholt commented Apr 8, 2024

Hmm, sounds like something funky with the test suite. I'll look into it, but your change seems sound.

@sorairolake
Copy link
Contributor Author

Both lz4 and lzip starts with "lz". So I think this may be related.

lzip.go Outdated
var mr MatchResult

// match filename
if strings.Contains(strings.ToLower(filename), lz.Name()) {
Copy link
Owner

Choose a reason for hiding this comment

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

Ah, indeed -- make this comparison more strict and that should hopefully fix the test.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think this can be fixed with the following changes:

Suggested change
if strings.Contains(strings.ToLower(filename), lz.Name()) {
if filepath.Ext(strings.ToLower(filename)) == lz.Name() {

However, this requires that the extension be the last element of the path.

Copy link
Owner

@mholt mholt Apr 8, 2024

Choose a reason for hiding this comment

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

That would fail for those cases as you say, but maybe a check for both a suffix of .lz or the string contains .lz.?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think there is almost no possibility that .lz and .lz4 exists anywhere other than at the end of the path.

I think /path/to/foo.tar.lz or bar.7z.lz4 are possible, but /path/to/foo.lz.tar or bar.lz4.7z are almost impossible.

Copy link
Owner

Choose a reason for hiding this comment

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

That's a good point.

lz4.go Outdated
@@ -23,7 +24,7 @@ func (lz Lz4) Match(filename string, stream io.Reader) (MatchResult, error) {
var mr MatchResult

// match filename
if strings.Contains(strings.ToLower(filename), lz.Name()) {
if filepath.Ext(strings.ToLower(filename)) == lz.Name() {
Copy link
Owner

Choose a reason for hiding this comment

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

Why was this one changed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought this would be a conflict, but it was a misunderstanding. So I restored this.

Copy link
Owner

@mholt mholt left a comment

Choose a reason for hiding this comment

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

Awesome, looks good now :) Thank you!

@mholt mholt merged commit de08bfa into mholt:master Apr 8, 2024
3 checks passed
@mholt
Copy link
Owner

mholt commented Apr 8, 2024

PS. I hope to travel to Japan someday :D

@sorairolake sorairolake deleted the add-lzip-support branch April 8, 2024 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add lzip support
2 participants