This repository has been archived by the owner on Nov 19, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 389
Add lzip support #401
Merged
Merged
Add lzip support #401
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
package archiver | ||
|
||
import ( | ||
"bytes" | ||
"io" | ||
"strings" | ||
|
||
"github.com/sorairolake/lzip-go" | ||
) | ||
|
||
func init() { | ||
RegisterFormat(Lzip{}) | ||
} | ||
|
||
// Lzip facilitates lzip compression. | ||
type Lzip struct{} | ||
|
||
func (Lzip) Name() string { return ".lz" } | ||
|
||
func (lz Lzip) Match(filename string, stream io.Reader) (MatchResult, error) { | ||
var mr MatchResult | ||
|
||
// match filename | ||
if strings.Contains(strings.ToLower(filename), lz.Name()) { | ||
mr.ByName = true | ||
} | ||
|
||
// match file header | ||
buf, err := readAtMost(stream, len(lzipHeader)) | ||
if err != nil { | ||
return mr, err | ||
} | ||
mr.ByStream = bytes.Equal(buf, lzipHeader) | ||
|
||
return mr, nil | ||
} | ||
|
||
func (Lzip) OpenWriter(w io.Writer) (io.WriteCloser, error) { | ||
return lzip.NewWriter(w), nil | ||
} | ||
|
||
func (Lzip) OpenReader(r io.Reader) (io.ReadCloser, error) { | ||
lzr, err := lzip.NewReader(r) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return io.NopCloser(lzr), err | ||
} | ||
|
||
// magic number at the beginning of lzip files | ||
// https://datatracker.ietf.org/doc/html/draft-diaz-lzip-09#section-2 | ||
var lzipHeader = []byte("LZIP") |
Oops, something went wrong.
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.
Ah, indeed -- make this comparison more strict and that should hopefully fix the test.
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 this can be fixed with the following changes:
However, this requires that the extension be the last element of the path.
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 would fail for those cases as you say, but maybe a check for both a suffix of
.lz
or the string contains.lz.
?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 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
orbar.7z.lz4
are possible, but/path/to/foo.lz.tar
orbar.lz4.7z
are almost impossible.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 a good point.