亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

directory search
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結構heap) container/list(容器數(shù)據(jù)結構list) container/ring(容器數(shù)據(jù)結構ring) context context(上下文) crypto crypto(加密) crypto/aes(加密/aes) crypto/cipher(加密/cipher) crypto/des(加密/des) crypto/dsa(加密/dsa) crypto/ecdsa(加密/ecdsa) crypto/elliptic(加密/elliptic) crypto/hmac(加密/hmac) crypto/md5(加密/md5) crypto/rand(加密/rand) crypto/rc4(加密/rc4) crypto/rsa(加密/rsa) crypto/sha1(加密/sha1) crypto/sha256(加密/sha256) crypto/sha512(加密/sha512) crypto/subtle(加密/subtle) crypto/tls(加密/tls) crypto/x509(加密/x509) crypto/x509/pkix(加密/x509/pkix) database database/sql(數(shù)據(jù)庫/sql) database/sql/driver(數(shù)據(jù)庫/sql/driver) debug debug/dwarf(調試/dwarf) debug/elf(調試/elf) debug/gosym(調試/gosym) debug/macho(調試/macho) debug/pe(調試/pe) debug/plan9obj(調試/plan9obj) encoding encoding(編碼) encoding/ascii85(編碼/ascii85) encoding/asn1(編碼/asn1) encoding/base32(編碼/base32) encoding/base64(編碼/base64) encoding/binary(編碼/binary) encoding/csv(編碼/csv) encoding/gob(編碼/gob) encoding/hex(編碼/hex) encoding/json(編碼/json) encoding/pem(編碼/pem) encoding/xml(編碼/xml) errors errors(錯誤) expvar expvar flag flag(命令行參數(shù)解析flag包) fmt fmt go go/ast(抽象語法樹) go/build go/constant(常量) go/doc(文檔) go/format(格式) go/importer go/parser go/printer go/scanner(掃描儀) go/token(令牌) go/types(類型) hash hash(散列) hash/adler32 hash/crc32 hash/crc64 hash/fnv html html html/template(模板) image image(圖像) image/color(顏色) image/color/palette(調色板) image/draw(繪圖) image/gif image/jpeg image/png index index/suffixarray io io io/ioutil log log log/syslog(日志系統(tǒng)) math math math/big math/big math/bits math/bits math/cmplx math/cmplx math/rand math/rand mime mime mime/multipart(多部分) mime/quotedprintable net net net/http net/http net/http/cgi net/http/cookiejar net/http/fcgi net/http/httptest net/http/httptrace net/http/httputil net/http/internal net/http/pprof net/mail net/mail net/rpc net/rpc net/rpc/jsonrpc net/smtp net/smtp net/textproto net/textproto net/url net/url os os os/exec os/signal os/user path path path/filepath(文件路徑) plugin plugin(插件) reflect reflect(反射) regexp regexp(正則表達式) regexp/syntax runtime runtime(運行時) runtime/debug(調試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
characters

  • import "archive/zip"

  • 概述

  • 索引

  • 例子

概述

Zip 壓縮包提供了對讀取和寫入 ZIP 壓縮文件的支持。

請參閱:https://www.pkware.com/appnote

該軟件包不支持磁盤跨越。

有關 ZIP64 的說明:

為了向后兼容,F(xiàn)ileHeader 具有32位和64位大小字段。64位字段將始終包含正確的值,對于普通存檔,這兩個字段都是相同的。對于需要 ZIP64 格式的文件,32位字段將為0xffffffff,必須使用64位字段。

索引

Constants

Variables

func RegisterCompressor(method uint16, comp Compressor)

func RegisterDecompressor(method uint16, dcomp Decompressor)

type Compressor

type Decompressor

type File

  • func (f *File) DataOffset() (offset int64, err error)

  • func (f *File) Open() (io.ReadCloser, error)

type FileHeader

  • func FileInfoHeader(fi os.FileInfo) (*FileHeader, error)

  • func (h *FileHeader) FileInfo() os.FileInfo

  • func (h *FileHeader) ModTime() time.Time

  • func (h *FileHeader) Mode() (mode os.FileMode)

  • func (h *FileHeader) SetModTime(t time.Time)

  • func (h *FileHeader) SetMode(mode os.FileMode)

type ReadCloser

  • func OpenReader(name string) (*ReadCloser, error)

  • func (rc *ReadCloser) Close() error

type Reader

  • func NewReader(r io.ReaderAt, size int64) (*Reader, error)

  • func (z *Reader) RegisterDecompressor(method uint16, dcomp Decompressor)

type Writer

  • func NewWriter(w io.Writer) *Writer

  • func (w *Writer) Close() error

  • func (w *Writer) Create(name string) (io.Writer, error)

  • func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)

  • func (w *Writer) Flush() error

  • func (w *Writer) RegisterCompressor(method uint16, comp Compressor)

  • func (w *Writer) SetOffset(n int64)

示例

Reader

Writer

Writer.RegisterCompressor

包文件

reader.go register.go struct.go writer.go

常量

壓縮方法。

const (
        Store   uint16 = 0
        Deflate uint16 = 8)

變量

var (
        ErrFormat    = errors.New("zip: not a valid zip file")
        ErrAlgorithm = errors.New("zip: unsupported compression algorithm")
        ErrChecksum  = errors.New("zip: checksum error"))

func RegisterCompressor

func RegisterCompressor(method uint16, comp Compressor)

RegisterCompressor 為指定的方法ID注冊自定義壓縮器。內置常用方法 Store 和 Deflate 。

func RegisterDecompressor

func RegisterDecompressor(method uint16, dcomp Decompressor)

RegisterDecompressor 允許為指定的方法ID定制解壓縮器。內置常用方法 Store 和 Deflate 。

type Compressor

Compressor 返回一個新的壓縮作家,寫入 w。必須使用WriteCloser 的 Close 方法將未處理的數(shù)據(jù)刷新到w。Compressor 本身必須可以安全地從多個 goroutine 同時調用,但每個返回的作者一次只能由一個 goroutine 使用。

type Compressor func(w io.Writer) (io.WriteCloser, error)

type Decompressor

解壓縮器返回一個新的解壓縮讀取器,從 r 讀取。 ReadCloser 的 Close 方法必須用于釋放相關資源。解壓縮器本身必須可以安全地從多個 goroutine 同時調用,但每個返回的讀取器一次只能由一個 goroutine 使用。

type Decompressor func(r io.Reader) io.ReadCloser

type File

type File struct {
        FileHeader        // 包含過濾或未導出的字段}

func (*File) DataOffset

func (f *File) DataOffset() (offset int64, err error)

DataOffset 返回文件的可能壓縮數(shù)據(jù),相對于 zip 文件開頭的偏移量。

大多數(shù)調用者應該使用 Open ,這會透明地解壓縮數(shù)據(jù)并驗證校驗和。

func (*File) Open

func (f *File) Open() (io.ReadCloser, error)

Open 返回一個 ReadCloser ,它提供對文件內容的訪問??梢酝瑫r讀取多個文件。

type FileHeader

FileHeader 描述了一個 zip 文件中的文件。有關詳細信息,請參閱 zip 規(guī)范。

type FileHeader struct {        // 名稱是文件的名稱。        // 它必須是相對路徑:它不能以驅動器啟動        // 字母(例如C:)或前導斜線,并且只有正斜杠        // 允許。
        Name string

        CreatorVersion     uint16
        ReaderVersion      uint16
        Flags              uint16
        Method             uint16
        ModifiedTime       uint16 // MS-DOS time
        ModifiedDate       uint16 // MS-DOS date
        CRC32              uint32
        CompressedSize     uint32 // 棄用:改用CompressedSize64。
        UncompressedSize   uint32 // 棄用:改用UncompressedSize64。
        CompressedSize64   uint64
        UncompressedSize64 uint64
        Extra              []byte
        ExternalAttrs      uint32 // 含義取決于Creator版本
        Comment            string}

func FileInfoHeader

func FileInfoHeader(fi os.FileInfo) (*FileHeader, error)

FileInfoHeader 從 os.FileInfo 創(chuàng)建一個部分填充的FileHeader 。因為 os.FileInfo 的 Name 方法僅返回它描述的文件的基本名稱,所以可能需要修改返回的頭的 Name 字段以提供文件的完整路徑名。

func (*FileHeader) FileInfo

func (h *FileHeader) FileInfo() os.FileInfo

FileInfo 為 FileHeader 返回一個os.FileInfo。

func (*FileHeader) ModTime

func (h *FileHeader) ModTime() time.Time

ModTime 返回 UTC 的修改時間。分辨率是2s。

func (*FileHeader) Mode

func (h *FileHeader) Mode() (mode os.FileMode)

模式返回 FileHeader 的權限和模式位。

func (*FileHeader) SetModTime

func (h *FileHeader) SetModTime(t time.Time)

SetModTime 將 ModifiedTime 和 ModifiedDate 字段設置為UTC 中給定的時間。分辨率是2s。

func (*FileHeader) SetMode

func (h *FileHeader) SetMode(mode os.FileMode)

SetMode 更改 FileHeader 的權限和模式位。

type ReadCloser

type ReadCloser struct {
        Reader        // 包含過濾或未導出的字段}

func OpenReader

func OpenReader(name string) (*ReadCloser, error)

OpenReader 將打開由名稱指定的 Zip 文件并返回一個ReadCloser 。

func (*ReadCloser) Close

func (rc *ReadCloser) Close() error

Close 關閉 Zip 文件,使其不能用于I/O。

type Reader

type Reader struct {
        File    []*File
        Comment string        // 包含過濾或未導出的字段}

示例

代碼:

// 打開一個zip文件供閱讀。r, err := zip.OpenReader("testdata/readme.zip")if err != nil {
        log.Fatal(err)}defer r.Close()// 遍歷存檔中的文件,// 打印他們的一些內容。for _, f := range r.File {
        fmt.Printf("Contents of %s:\n", f.Name)
        rc, err := f.Open()        if err != nil {
                log.Fatal(err)        }
        _, err = io.CopyN(os.Stdout, rc, 68)        if err != nil {
                log.Fatal(err)        }
        rc.Close()
        fmt.Println()}

輸出:

Contents of README:This is the source code repository for the Go programming language.

func NewReader

func NewReader(r io.ReaderAt, size int64) (*Reader, error)

NewReader 從 r 返回一個新的 Reader 讀數(shù),它被假定為具有給定的字節(jié)大小。

func (*Reader) RegisterDecompressor

func (z *Reader) RegisterDecompressor(method uint16, dcomp Decompressor)

RegisterDecompressor 注冊或覆蓋特定方法 ID 的自定義解壓縮程序。如果找不到給定方法的解壓縮程序,則 Reader 將默認在包級別查找解壓縮程序。

type Writer

Writer 實現(xiàn)了一個 zip 文件編寫器。

type Writer struct {        // 包含過濾或未導出的字段}

示例

代碼:

// 創(chuàng)建一個緩沖區(qū)來寫入我們的存檔。buf := new(bytes.Buffer)// 創(chuàng)建一個新的zip存檔。w := zip.NewWriter(buf)// 將一些文件添加到存檔中。將一些文件添加到存檔中。var files = []struct {
        Name, Body string}{        {"readme.txt", "This archive contains some text files."},        {"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},        {"todo.txt", "Get animal handling licence.\nWrite more examples."},}for _, file := range files {
        f, err := w.Create(file.Name)        if err != nil {
                log.Fatal(err)        }
        _, err = f.Write([]byte(file.Body))        if err != nil {
                log.Fatal(err)        }}// 確保在Close時檢查錯誤。err := w.Close()if err != nil {
        log.Fatal(err)}

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter 返回一個新的 Writer 向w寫一個zip文件。

func (*Writer) Close

func (w *Writer) Close() error

關閉通過編寫中央目錄完成編寫 zip 文件。它沒有(也不能)關閉潛在的寫者。

func (*Writer) Create

func (w *Writer) Create(name string) (io.Writer, error)

創(chuàng)建使用提供的名稱將文件添加到 zip 文件。它返回一個寫入文件內容的 Writer。該名稱必須是相對路徑:不能以驅動器號(例如C:)或前導斜杠開頭,并且只允許正斜杠。在下一次調用 Create,CreateHeader 或 Close之前,必須將文件的內容寫入 io.Writer。

func (*Writer) CreateHeader

func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)

CreateHeader 使用提供的 FileHeader 為文件元數(shù)據(jù)添加一個文件到 zip 文件。它返回一個寫入文件內容的 Writer 。

在下一次調用 Create, CreateHeader 或 Close 之前,必須將文件的內容寫入 io.Writer。在調用 CreateHeader 之后,不得修改提供的 FileHeader fh。

func (*Writer) Flush

func (w *Writer) Flush() error

刷新將任何緩沖的數(shù)據(jù)刷新到底層寫入器。調用刷新通常不是必需的;調用 Close 就足夠了。

func (*Writer) RegisterCompressor

func (w *Writer) RegisterCompressor(method uint16, comp Compressor)

RegisterCompressor 為特定方法 ID 注冊或覆蓋自定義壓縮器。如果沒有找到給定方法的壓縮器,Writer 將默認在包裝級查找壓縮器。

示例

package mainimport ("archive/zip""bytes""compress/flate""io")func main() {// 用較高的壓縮級別覆蓋默認的Deflate壓縮器。// 創(chuàng)建一個緩沖區(qū)來寫入我們的存檔。
	buf := new(bytes.Buffer)// 創(chuàng)建一個新的zip存檔。
	w := zip.NewWriter(buf)// 注冊一個自定義的Deflate壓縮機。
	w.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {return flate.NewWriter(out, flate.BestCompression)})// 繼續(xù)向w添加文件。}

func (*Writer) SetOffset

func (w *Writer) SetOffset(n int64)

SetOffset 設置底層編寫器中壓縮數(shù)據(jù)開始的偏移量。應將zip數(shù)據(jù)附加到現(xiàn)有文件(例如二進制可執(zhí)行文件)時使用,且必須在寫入任何數(shù)據(jù)之前調用。

Previous article: Next article: