https://github.com/saracen/go7z
A native Go 7z archive reader.
https://github.com/saracen/go7z
7z 7zip archive bcj2 bzip2 compression golang lzma2
Last synced: 4 months ago
JSON representation
A native Go 7z archive reader.
- Host: GitHub
- URL: https://github.com/saracen/go7z
- Owner: saracen
- License: mit
- Created: 2018-07-17T18:57:25.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-10T11:02:05.000Z (almost 6 years ago)
- Last Synced: 2024-12-24T22:03:03.789Z (over 1 year ago)
- Topics: 7z, 7zip, archive, bcj2, bzip2, compression, golang, lzma2
- Language: Go
- Size: 20.5 KB
- Stars: 55
- Watchers: 4
- Forks: 12
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# go7z
A native Go 7z archive reader.
Features:
- Development in early stages.
- Very little tests.
- Medium probability of crashes.
- Medium probability of using all memory.
- Decompresses:
- [LZMA](https://github.com/ulikunitz/xz)
- [LZMA2](https://github.com/ulikunitz/xz)
- Delta
- BCJ2
- bzip2
- deflate
## Usage
Extracting an archive:
```
package main
import (
"io"
"os"
"github.com/saracen/go7z"
)
func main() {
sz, err := go7z.OpenReader("hello.7z")
if err != nil {
panic(err)
}
defer sz.Close()
for {
hdr, err := sz.Next()
if err == io.EOF {
break // End of archive
}
if err != nil {
panic(err)
}
// If empty stream (no contents) and isn't specifically an empty file...
// then it's a directory.
if hdr.IsEmptyStream && !hdr.IsEmptyFile {
if err := os.MkdirAll(hdr.Name, os.ModePerm); err != nil {
panic(err)
}
continue
}
// Create file
f, err := os.Create(hdr.Name)
if err != nil {
panic(err)
}
defer f.Close()
if _, err := io.Copy(f, sz); err != nil {
panic(err)
}
}
}
```