代码拉取完成,页面将自动刷新
// Package archive provides tar.gz and zip archiving
package archive
import (
"fmt"
"gitee.com/h79/goutils/common/archive/gzip"
"gitee.com/h79/goutils/common/archive/tar"
"gitee.com/h79/goutils/common/archive/targz"
"gitee.com/h79/goutils/common/archive/tarxz"
"gitee.com/h79/goutils/common/archive/zip"
fileconfig "gitee.com/h79/goutils/common/file/config"
"io"
"os"
)
// Archive represents a compression archive files from disk can be written to.
type Archive interface {
Close() error
Add(f fileconfig.File, stream ...fileconfig.ReaderStream) error
}
type Object interface {
New(w io.Writer) Archive
Coping(r *os.File, w io.Writer) (Archive, error)
}
func Register(format string, obj Object) {
reg[format] = obj
}
var reg map[string]Object = make(map[string]Object)
// New archive.
func New(w io.Writer, format string) (Archive, error) {
switch format {
case "tar.gz", "tgz":
return targz.New(w), nil
case "tar":
return tar.New(w), nil
case "gz":
return gzip.New(w), nil
case "tar.xz", "txz":
return tarxz.New(w), nil
case "zip":
return zip.New(w), nil
default:
if n, ok := reg[format]; ok {
return n.New(w), nil
}
}
return nil, fmt.Errorf("invalid archive format: %s", format)
}
// Copying copies the source archive into a new one, which can be appended at.
// Source needs to be in the specified format.
func Copying(r *os.File, w io.Writer, format string) (Archive, error) {
switch format {
case "tar.gz", "tgz":
return targz.Copying(r, w)
case "tar":
return tar.Copying(r, w)
case "zip":
return zip.Copying(r, w)
default:
if n, ok := reg[format]; ok {
return n.Coping(r, w)
}
}
return nil, fmt.Errorf("invalid archive format: %s", format)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。