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

目錄 搜尋
archive archive/tar archive/zip bufio bufio(緩存) builtin builtin(內(nèi)置包) bytes bytes(包字節(jié)) compress compress/bzip2(壓縮/bzip2) compress/flate(壓縮/flate) compress/gzip(壓縮/gzip) compress/lzw(壓縮/lzw) compress/zlib(壓縮/zlib) container container/heap(容器數(shù)據(jù)結(jié)構(gòu)heap) container/list(容器數(shù)據(jù)結(jié)構(gòu)list) container/ring(容器數(shù)據(jù)結(jié)構(gòu)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(調(diào)試/dwarf) debug/elf(調(diào)試/elf) debug/gosym(調(diào)試/gosym) debug/macho(調(diào)試/macho) debug/pe(調(diào)試/pe) debug/plan9obj(調(diào)試/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(錯(cuò)誤) 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(調(diào)色板) 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(正則表達(dá)式) regexp/syntax runtime runtime(運(yùn)行時(shí)) runtime/debug(調(diào)試) runtime/internal/sys runtime/pprof runtime/race(競爭) runtime/trace(執(zhí)行追蹤器) sort sort(排序算法) strconv strconv(轉(zhuǎn)換) strings strings(字符串) sync sync(同步) sync/atomic(原子操作) syscall syscall(系統(tǒng)調(diào)用) testing testing(測試) testing/iotest testing/quick text text/scanner(掃描文本) text/tabwriter text/template(定義模板) text/template/parse time time(時(shí)間戳) unicode unicode unicode/utf16 unicode/utf8 unsafe unsafe
文字

  • import "compress/gzip"

  • 概述

  • 索引

  • 示例

概述

軟件包 gzip 實(shí)現(xiàn)讀寫 gzip 格式壓縮文件,如RFC 1952中所述。

示例(WriterReader)

package mainimport ("bytes""compress/gzip""fmt""io""log""os""time")func main() {var buf bytes.Buffer
	zw := gzip.NewWriter(&buf)// 設(shè)置標(biāo)題字段是可選的。
	zw.Name = "a-new-hope.txt"
	zw.Comment = "an epic space opera by George Lucas"
	zw.ModTime = time.Date(1977, time.May, 25, 0, 0, 0, 0, time.UTC)

	_, err := zw.Write([]byte("A long time ago in a galaxy far, far away..."))if err != nil {
		log.Fatal(err)}if err := zw.Close(); err != nil {
		log.Fatal(err)}

	zr, err := gzip.NewReader(&buf)if err != nil {
		log.Fatal(err)}

	fmt.Printf("Name: %s\nComment: %s\nModTime: %s\n\n", zr.Name, zr.Comment, zr.ModTime.UTC())if _, err := io.Copy(os.Stdout, zr); err != nil {
		log.Fatal(err)}if err := zr.Close(); err != nil {
		log.Fatal(err)}}

索引

Constants(常量)

Variables(變量)

type Header

type Reader

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

  • func (z *Reader) Close() error

  • func (z *Reader) Multistream(ok bool)

  • func (z *Reader) Read(p []byte) (n int, err error)

  • func (z *Reader) Reset(r io.Reader) error

type Writer

  • func NewWriter(w io.Writer) *Writer

  • func NewWriterLevel(w io.Writer, level int) (*Writer, error)

  • func (z *Writer) Close() error

  • func (z *Writer) Flush() error

  • func (z *Writer) Reset(w io.Writer)

  • func (z *Writer) Write(p []byte) (int, error)

示例

Reader.Multistream Package (WriterReader)

打包文件

gunzip.go gzip.go

常量

這些常量是從 flate 包中復(fù)制,因此導(dǎo)入“compress/gzip”的代碼不需要導(dǎo)入“compress/flate”。

const (
        NoCompression      = flate.NoCompression
        BestSpeed          = flate.BestSpeed
        BestCompression    = flate.BestCompression
        DefaultCompression = flate.DefaultCompression
        HuffmanOnly        = flate.HuffmanOnly)

變量

var (        // 讀取具有無效校驗(yàn)和的GZIP數(shù)據(jù)時(shí),會(huì)返回ErrChecksum。
        ErrChecksum = errors.New("gzip: invalid checksum")        // 讀取包含無效標(biāo)題的GZIP數(shù)據(jù)時(shí)將返回ErrHeader。
        ErrHeader = errors.New("gzip: invalid header"))

type Header

gzip 文件存儲(chǔ)一個(gè)頭文件,提供有關(guān)壓縮文件的元數(shù)據(jù)。這個(gè)頭文件在 Writer 和 Reader 的字段結(jié)構(gòu)中暴露出來。

由于 GZIP 文件格式的限制,字符串必須是UTF-8編碼,并且可能只包含U + 0001到U + 00FF的 Unicode 代碼點(diǎn)。

type Header struct {
        Comment string    // 注解
        Extra   []byte    // “額外數(shù)據(jù)”
        ModTime time.Time // 修改時(shí)間
        Name    string    // 文件名
        OS      byte      // 操作系統(tǒng)類型}

type Reader

Reader 是一個(gè) io.Reader,可以讀取它從 gzip 格式的壓縮文件中檢索未壓縮的數(shù)據(jù)。

通常,gzip 文件可以是 gzip 文件的連接,每個(gè)文件都有自己的頭文件。從 Reader 讀取返回每個(gè)的未壓縮數(shù)據(jù)的連接。只有第一個(gè)標(biāo)題被記錄在 Reader 字段中。

Gzip 文件存儲(chǔ)未壓縮數(shù)據(jù)的長度和校驗(yàn)和。如果 Read未達(dá)到預(yù)期的長度或校驗(yàn)和,Reader 將在 Read 達(dá)到未壓縮數(shù)據(jù)的末尾時(shí)返回 ErrChecksum。客戶應(yīng)將由 Read 返回的數(shù)據(jù)視為臨時(shí)數(shù)據(jù),直到他們收到標(biāo)記數(shù)據(jù)結(jié)束的 io.EOF。

type Reader struct {
        Header // 在NewReader或Reader.Reset之后有效        // 包含過濾或未導(dǎo)出的字段}

func NewReader

func NewReader(r io.Reader) (*Reader, error)

NewReader 創(chuàng)建一個(gè)閱讀給定閱讀器的新 Reader。如果 r 不執(zhí)行io.ByteReader,則解壓縮程序可能從 r 讀取比所需更多的數(shù)據(jù)。

完成后 caller 有責(zé)任在 Reader 上調(diào)用 Close。

Reader.Header 字段將在返回的 Reader中有效。

func (*Reader) Close

func (z *Reader) Close() error

關(guān)閉 Reader。它不會(huì)關(guān)閉底層的 io.Reader。為了驗(yàn)證 GZIP校驗(yàn)和,閱讀器必須充分消耗,直到 io.EOF。

func (*Reader) Multistream

func (z *Reader) Multistream(ok bool)

多流控制閱讀器是否支持多流文件。

如果啟用(the default 默認(rèn)),則 Reader 將輸入為單獨(dú)壓縮數(shù)據(jù)流的序列,每個(gè)數(shù)據(jù)流都有自己的頭和尾部,以 EOF 結(jié)尾。其效果是將一系列 gzip 文件的串聯(lián)視為等同于串聯(lián)的 gzip。這是 gzip 閱讀器的標(biāo)準(zhǔn)行為。

調(diào)用 Multistream(false)會(huì)禁用此行為;在閱讀區(qū)分各個(gè) gzip 數(shù)據(jù)流或?qū)?gzip 數(shù)據(jù)流與其他數(shù)據(jù)流混合的文件格式時(shí),禁用此行為可能很有用。在這種模式下,當(dāng) Reader到達(dá)數(shù)據(jù)流的末尾時(shí),Reader 返回 io.EOF。如果底層的閱讀器實(shí)現(xiàn) io.ByteReader,它將被放置在 gzip 流的后面。要開始下一個(gè)流,請(qǐng)調(diào)用z.Reset(r),然后再調(diào)用 z.Multistream(false)。如果沒有下一個(gè)流,則 z.Reset(r)將返回 io.EOF。

示例

package mainimport ("bytes""compress/gzip""fmt""io""log""os""time")func main() {var buf bytes.Buffer
	zw := gzip.NewWriter(&buf)var files = []struct {
		name    string
		comment string
		modTime time.Time
		data    string}{{"file-1.txt", "file-header-1", time.Date(2006, time.February, 1, 3, 4, 5, 0, time.UTC), "Hello Gophers - 1"},{"file-2.txt", "file-header-2", time.Date(2007, time.March, 2, 4, 5, 6, 1, time.UTC), "Hello Gophers - 2"},}for _, file := range files {
		zw.Name = file.name
		zw.Comment = file.comment
		zw.ModTime = file.modTimeif _, err := zw.Write([]byte(file.data)); err != nil {
			log.Fatal(err)}if err := zw.Close(); err != nil {
			log.Fatal(err)}

		zw.Reset(&buf)}

	zr, err := gzip.NewReader(&buf)if err != nil {
		log.Fatal(err)}for {
		zr.Multistream(false)
		fmt.Printf("Name: %s\nComment: %s\nModTime: %s\n\n", zr.Name, zr.Comment, zr.ModTime.UTC())if _, err := io.Copy(os.Stdout, zr); err != nil {
			log.Fatal(err)}

		fmt.Print("\n\n")

		err = zr.Reset(&buf)if err == io.EOF {break}if err != nil {
			log.Fatal(err)}}if err := zr.Close(); err != nil {
		log.Fatal(err)}}

func (*Reader) Read

func (z *Reader) Read(p []byte) (n int, err error)

Read 實(shí)現(xiàn) io.Reader,從其底層 Reader 讀取未壓縮的字節(jié)。

func (*Reader) Reset

func (z *Reader) Reset(r io.Reader) error

重置將丟棄 Reader z的狀態(tài),并使其等同于 NewReader 中原始狀態(tài)的結(jié)果,而是從 r 讀取 。這允許重新使用 Reader 而不是分配新的 Reader。

type Writer

Writer 是一個(gè) io.WriteCloser。寫入 Writer 被壓縮并寫入w。

type Writer struct {
        Header // 在第一次寫入Write,F(xiàn)lush或Close時(shí)寫入        // 包含過濾或未導(dǎo)出的字段}

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter 返回一個(gè)新的 Writer。寫入返回的 writer 將被壓縮并寫入 w。

調(diào)用者有責(zé)任在完成時(shí)調(diào)用 WriteCloser 上的 Close。寫入可能會(huì)被緩沖,直到關(guān)閉才會(huì)被刷新。

希望在 Writer.Header 中設(shè)置字段的調(diào)用者必須在首次調(diào)用Write,F(xiàn)lush 或 Close之前執(zhí)行此操作。

func NewWriterLevel

func NewWriterLevel(w io.Writer, level int) (*Writer, error)

NewWriterLevel 就像 NewWriter,但指定壓縮級(jí)別,而不是假設(shè) DefaultCompression。

壓縮級(jí)別可以是 DefaultCompression,NoCompression,HuffmanOnly 或 BestSpeed 和 BestCompression 之間的任何整數(shù)值。如果級(jí)別有效,返回的錯(cuò)誤將為零。

func (*Writer) Close

func (z *Writer) Close() error

通過將任何未寫入的數(shù)據(jù)清空到底層的 io.Writer 并寫入GZIP頁腳,Close 關(guān)閉 Writer。它不關(guān)閉潛在的 io.Writer。

func (*Writer) Flush

func (z *Writer) Flush() error

刷新將任何未決的壓縮數(shù)據(jù)刷新到底層寫入器。

它主要用于壓縮網(wǎng)絡(luò)協(xié)議,以確保遠(yuǎn)程讀取器有足夠的數(shù)據(jù)來重建數(shù)據(jù)包。在數(shù)據(jù)寫入之前,刷新不會(huì)返回。如果底層編寫器返回錯(cuò)誤,F(xiàn)lush 將返回該錯(cuò)誤。

在zlib庫的術(shù)語中,F(xiàn)lush 等價(jià)于 Z_SYNC_FLUSH。

func (*Writer) Reset

func (z *Writer) Reset(w io.Writer)

重置放棄 Writer z 的狀態(tài),并使其等同于 NewWriter 或NewWriterLevel 的原始狀態(tài)的結(jié)果,而是寫入 w。這允許重新使用 Writer 而不是分配新的。

func (*Writer) Write

func (z *Writer) Write(p []byte) (int, error)

寫入一個(gè)壓縮形式的 p 到底層的 io.Writer 。在 Writer 關(guān)閉之前,壓縮的字節(jié)不一定會(huì)被刷新。

上一篇: 下一篇: