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 390
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
43a073e
commit 699b325
Showing
8 changed files
with
71 additions
and
8 deletions.
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") |