mssqlbulkloader/archivetypes.go

59 lines
985 B
Go
Raw Permalink Normal View History

2023-04-03 19:12:30 +05:00
package main
import (
"fmt"
)
type ArchiveType int
const (
AutoDetectArchiveType ArchiveType = iota
Zip
2023-04-17 20:30:54 +05:00
Zstd
2023-04-03 19:12:30 +05:00
)
type ArchiveProcessor interface {
Process(options *Options) error
}
func (ft ArchiveType) MarshalText() (text []byte, err error) {
switch ft {
case AutoDetectArchiveType:
return []byte("auto"), nil
case Zip:
return []byte("zip"), nil
2023-04-17 20:30:54 +05:00
case Zstd:
return []byte("zstd"), nil
2023-04-03 19:12:30 +05:00
}
return nil, fmt.Errorf("unknown type id = %d", ft)
}
func (ft ArchiveType) Open() (ArchiveProcessor, error) {
switch ft {
case AutoDetectArchiveType:
case Zip:
return new(ZipReader), nil
2023-04-17 20:30:54 +05:00
case Zstd:
return new(ZstdReader), nil
2023-04-03 19:12:30 +05:00
}
return nil, fmt.Errorf("unknown type id = %d", ft)
}
func (ft *ArchiveType) UnmarshalText(text []byte) error {
switch string(text) {
case "auto":
*ft = AutoDetectArchiveType
return nil
case "zip":
*ft = Zip
return nil
2023-04-17 20:30:54 +05:00
case "zstd":
*ft = Zstd
return nil
2023-04-03 19:12:30 +05:00
}
return fmt.Errorf(`unknown format code "%s"`, string(text))
}