https://github.com/pashifika/compress
a go compress library for fs.FS interface
https://github.com/pashifika/compress
archiver go golang rar zip
Last synced: 5 months ago
JSON representation
a go compress library for fs.FS interface
- Host: GitHub
- URL: https://github.com/pashifika/compress
- Owner: pashifika
- License: apache-2.0
- Created: 2022-01-17T01:16:25.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2022-01-17T05:34:24.000Z (over 4 years ago)
- Last Synced: 2024-06-20T11:51:59.824Z (about 2 years ago)
- Topics: archiver, go, golang, rar, zip
- Language: Go
- Homepage:
- Size: 39.1 KB
- Stars: 2
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
compress: a go compress library for fs.FS interface
===================================================
| Format | Test | Charset | Decoder | Encoder | Password | Info |
|--------|-------|---------|---------|---------|----------|------------------------------------------------------------------------------------------------|
| zip | local | true | true | true | false | used go std |
| rar | local | false | true | false | true | [rardecode/v2](http://github.com/nwaples/rardecode) |
| 7zip | false | false | true | false | true | not work in big file(>10M)
github.com/ulikunitz/xz/lzma.(*rangeDecoder).DecodeBit too slow |
## use
```
go get github.com/pashifika/compress
```
Example:
--------
```go
package main
import (
"bytes"
"fmt"
"io"
"io/fs"
"log"
"golang.org/x/text/encoding"
"golang.org/x/text/encoding/japanese"
"github.com/pashifika/compress"
_ "github.com/pashifika/compress/rar"
_ "github.com/pashifika/compress/zip"
)
func main() {
// set charset to decode zip header name
fsys := &compress.FileSystem{
Charset: []encoding.Encoding{japanese.ShiftJIS},
SkipCharErr: false,
}
path := "you test archive file path"
rc, err := fsys.Open(path)
if err != nil {
log.Fatal(err)
}
defer fsys.Close()
err = fs.WalkDir(rc, ".", func(path string, d fs.DirEntry, err error) error {
if err != nil {
return err
}
if d.IsDir() {
switch path {
case ".git":
return fs.SkipDir
case compress.DefaultArchiverRoot:
return nil
default:
fmt.Println("dir:", path)
return nil
}
}
if !d.IsDir() {
af, err := rc.Open(path)
if err != nil {
panic(err)
}
buf := bytes.Buffer{}
n, err := io.Copy(&buf, af)
if err != nil {
panic(err)
}
fmt.Println("file:", path)
fmt.Println(n, err, n, buf.Len())
}
return nil
})
if err != nil {
log.Fatal(err)
}
}
```