mirror of
https://github.com/nxshock/mssqlbulkloader.git
synced 2024-11-28 00:21:03 +05:00
Add Zstandard decompressor
This commit is contained in:
parent
22d99a40fd
commit
be675c1174
@ -9,6 +9,7 @@ type ArchiveType int
|
|||||||
const (
|
const (
|
||||||
AutoDetectArchiveType ArchiveType = iota
|
AutoDetectArchiveType ArchiveType = iota
|
||||||
Zip
|
Zip
|
||||||
|
Zstd
|
||||||
)
|
)
|
||||||
|
|
||||||
type ArchiveProcessor interface {
|
type ArchiveProcessor interface {
|
||||||
@ -21,6 +22,8 @@ func (ft ArchiveType) MarshalText() (text []byte, err error) {
|
|||||||
return []byte("auto"), nil
|
return []byte("auto"), nil
|
||||||
case Zip:
|
case Zip:
|
||||||
return []byte("zip"), nil
|
return []byte("zip"), nil
|
||||||
|
case Zstd:
|
||||||
|
return []byte("zstd"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("unknown type id = %d", ft)
|
return nil, fmt.Errorf("unknown type id = %d", ft)
|
||||||
@ -31,6 +34,8 @@ func (ft ArchiveType) Open() (ArchiveProcessor, error) {
|
|||||||
case AutoDetectArchiveType:
|
case AutoDetectArchiveType:
|
||||||
case Zip:
|
case Zip:
|
||||||
return new(ZipReader), nil
|
return new(ZipReader), nil
|
||||||
|
case Zstd:
|
||||||
|
return new(ZstdReader), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, fmt.Errorf("unknown type id = %d", ft)
|
return nil, fmt.Errorf("unknown type id = %d", ft)
|
||||||
@ -44,6 +49,9 @@ func (ft *ArchiveType) UnmarshalText(text []byte) error {
|
|||||||
case "zip":
|
case "zip":
|
||||||
*ft = Zip
|
*ft = Zip
|
||||||
return nil
|
return nil
|
||||||
|
case "zstd":
|
||||||
|
*ft = Zstd
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Errorf(`unknown format code "%s"`, string(text))
|
return fmt.Errorf(`unknown format code "%s"`, string(text))
|
||||||
|
1
go.mod
1
go.mod
@ -10,6 +10,7 @@ require (
|
|||||||
github.com/urfave/cli v1.22.12
|
github.com/urfave/cli v1.22.12
|
||||||
github.com/xuri/excelize/v2 v2.7.0
|
github.com/xuri/excelize/v2 v2.7.0
|
||||||
golang.org/x/text v0.8.0
|
golang.org/x/text v0.8.0
|
||||||
|
github.com/klauspost/compress v1.16.5
|
||||||
)
|
)
|
||||||
|
|
||||||
require (
|
require (
|
||||||
|
2
go.sum
2
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/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 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A=
|
||||||
github.com/golang-sql/sqlexp v0.1.0/go.mod h1:J4ad9Vo8ZCWQ2GMrC4UCQy1JpCbwU9m3EOqtpKwwwHI=
|
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/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 h1:RWengNIwukTxcDr9M+97sNutRR1RKhG96O6jWumTTnw=
|
||||||
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826/go.mod h1:TaXosZuwdSHYgviHp1DAtfrULt5eUgsSMsZf+YrPgl8=
|
||||||
|
25
zstdreader.go
Normal file
25
zstdreader.go
Normal file
@ -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)
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user