diff --git a/archivetypes.go b/archivetypes.go index 00ffa26..4dad8f3 100644 --- a/archivetypes.go +++ b/archivetypes.go @@ -9,6 +9,7 @@ type ArchiveType int const ( AutoDetectArchiveType ArchiveType = iota Zip + Zstd ) type ArchiveProcessor interface { @@ -21,6 +22,8 @@ func (ft ArchiveType) MarshalText() (text []byte, err error) { return []byte("auto"), nil case Zip: return []byte("zip"), nil + case Zstd: + return []byte("zstd"), nil } return nil, fmt.Errorf("unknown type id = %d", ft) @@ -31,6 +34,8 @@ func (ft ArchiveType) Open() (ArchiveProcessor, error) { case AutoDetectArchiveType: case Zip: return new(ZipReader), nil + case Zstd: + return new(ZstdReader), nil } return nil, fmt.Errorf("unknown type id = %d", ft) @@ -44,6 +49,9 @@ func (ft *ArchiveType) UnmarshalText(text []byte) error { case "zip": *ft = Zip return nil + case "zstd": + *ft = Zstd + return nil } return fmt.Errorf(`unknown format code "%s"`, string(text)) diff --git a/go.mod b/go.mod index 212351d..8f44283 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,7 @@ require ( github.com/urfave/cli v1.22.12 github.com/xuri/excelize/v2 v2.7.0 golang.org/x/text v0.8.0 + github.com/klauspost/compress v1.16.5 ) require ( diff --git a/go.sum b/go.sum index ef0e636..42f42ff 100644 --- a/go.sum +++ b/go.sum @@ -19,6 +19,8 @@ github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0kt github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9/go.mod h1:8vg3r2VgvsThLBIFL93Qb5yWzgyZWhEmBwUJWevAkK0= github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI= +github.com/klauspost/compress v1.16.5 h1:IFV2oUNUzZaz+XyusxpLzpzS8Pt5rh0Z16For/djlyI= +github.com/klauspost/compress v1.16.5/go.mod h1:ntbaceVETuRiXiv4DpjP66DpAtAGkEQskQzEyD//IeE= github.com/modocache/gover v0.0.0-20171022184752-b58185e213c5/go.mod h1:caMODM3PzxT8aQXRPkAt8xlV/e7d7w8GM5g0fa5F0D8= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw= github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8= diff --git a/zstdreader.go b/zstdreader.go new file mode 100644 index 0000000..7c47f24 --- /dev/null +++ b/zstdreader.go @@ -0,0 +1,25 @@ +package main + +import ( + "os" + + "github.com/klauspost/compress/zstd" +) + +type ZstdReader struct{} + +func (zr *ZstdReader) Process(options *Options) error { + f, err := os.Open(options.filePath) + if err != nil { + return err + } + defer f.Close() + + r, err := zstd.NewReader(f) + if err != nil { + return err + } + defer r.Close() + + return process(f, options) +}