# package flate
`import "compress/flate"`
flate包實現了deflate壓縮數據格式,參見[RFC 1951](http://tools.ietf.org/html/rfc1951)。gzip包和zlib包實現了對基于deflate的文件格式的訪問。
## Index
* [Constants](#pkg-constants)
* [type CorruptInputError](#CorruptInputError)
* [func (e CorruptInputError) Error() string](#CorruptInputError.Error)
* [type InternalError](#InternalError)
* [func (e InternalError) Error() string](#InternalError.Error)
* [type ReadError](#ReadError)
* [func (e \*ReadError) Error() string](#ReadError.Error)
* [type WriteError](#WriteError)
* [func (e \*WriteError) Error() string](#WriteError.Error)
* [type Reader](#Reader)
* [func NewReader(r io.Reader) io.ReadCloser](#NewReader)
* [func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser](#NewReaderDict)
* [type Writer](#Writer)
* [func NewWriter(w io.Writer, level int) (\*Writer, error)](#NewWriter)
* [func NewWriterDict(w io.Writer, level int, dict []byte) (\*Writer, error)](#NewWriterDict)
* [func (w \*Writer) Reset(dst io.Writer)](#Writer.Reset)
* [func (w \*Writer) Write(data []byte) (n int, err error)](#Writer.Write)
* [func (w \*Writer) Flush() error](#Writer.Flush)
* [func (w \*Writer) Close() error](#Writer.Close)
## Constants
```
const (
NoCompression = 0
BestSpeed = 1
BestCompression = 9
DefaultCompression = -1
)
```
## type [CorruptInputError](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L26 "View Source")
```
type CorruptInputError int64
```
CorruptInputError表示在輸入的指定偏移量位置存在損壞。
### func (CorruptInputError) [Error](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L28 "View Source")
```
func (e CorruptInputError) Error() string
```
## type [InternalError](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L33 "View Source")
```
type InternalError string
```
InternalError表示flate數據自身的錯誤。
### func (InternalError) [Error](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L35 "View Source")
```
func (e InternalError) Error() string
```
## type [ReadError](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L38 "View Source")
```
type ReadError struct {
Offset int64 // 錯誤出現的位置(字節偏移量)
Err error // 下層的讀取操作返回的錯誤
}
```
ReadError代表在讀取輸入流時遇到的錯誤。
### func (\*ReadError) [Error](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L43 "View Source")
```
func (e *ReadError) Error() string
```
## type [WriteError](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L48 "View Source")
```
type WriteError struct {
Offset int64 // 錯誤出現的位置(字節偏移量)
Err error // 下層的寫入操作返回的錯誤
}
```
WriteError代表在寫入輸出流時遇到的錯誤。
### func (\*WriteError) [Error](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L53 "View Source")
```
func (e *WriteError) Error() string
```
## type [Reader](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L181 "View Source")
```
type Reader interface {
io.Reader
io.ByteReader
}
```
NewReader真正需要的接口。如果提供的Io.Reader沒有提供ReadByte方法,NewReader函數會自行添加緩沖。
### func [NewReader](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L684 "View Source")
```
func NewReader(r io.Reader) io.ReadCloser
```
NewReader返回一個從r讀取并解壓數據的io.ReadCloser。調用者有責任在讀取完畢后調用返回值的Close方法。
### func [NewReaderDict](https://github.com/golang/go/blob/master/src/compress/flate/inflate.go#L699 "View Source")
```
func NewReaderDict(r io.Reader, dict []byte) io.ReadCloser
```
NewReaderDict類似NewReader,但會使用預設的字典初始化返回的Reader。
返回的Reader表現的好像原始未壓縮的數據流以該字典起始(并已經被讀取)。NewReaderDict用于讀取NewWriterDict壓縮的數據。
## type [Writer](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L526 "View Source")
```
type Writer struct {
// 內含隱藏或非導出字段
}
```
Writer將提供給它的數據壓縮后寫入下層的io.Writer接口。
### func [NewWriter](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L485 "View Source")
```
func NewWriter(w io.Writer, level int) (*Writer, error)
```
NewWriter返回一個壓縮水平為level的Writer。
和zlib包一樣,level的范圍是1(BestSpeed)到9?(BestCompression)。值越大,壓縮效果越好,但也越慢;level為0表示不嘗試做任何壓縮,只添加必需的deflate框架;level為-1時會使用默認的壓縮水平;如果level在[-1, 9]范圍內,error返回值將是nil,否則將返回非nil的錯誤值。
### func [NewWriterDict](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L499 "View Source")
```
func NewWriterDict(w io.Writer, level int, dict []byte) (*Writer, error)
```
NewWriterDict類似NewWriter,但會使用預設的字典初始化返回的Writer。
返回的Writer表現的好像已經將原始、未壓縮數據dict(壓縮后未產生任何數據的)寫入w了,使用w壓縮的數據只能被使用同樣的字典初始化生成的Reader接口解壓縮。(類似加解密的初始向量/密鑰)
### func (\*Writer) [Reset](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L558 "View Source")
```
func (w *Writer) Reset(dst io.Writer)
```
Reset將w重置,丟棄當前的寫入狀態,并將下層輸出目標設為dst。效果上等價于將w設為使用dst和w的壓縮水平、字典重新調用NewWriter或NewWriterDict返回的\*Writer。
### func (\*Writer) [Write](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L533 "View Source")
```
func (w *Writer) Write(data []byte) (n int, err error)
```
Write向w寫入數據,最終會將壓縮后的數據寫入下層io.Writer接口。
### func (\*Writer) [Flush](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L544 "View Source")
```
func (w *Writer) Flush() error
```
Flush將緩沖中的壓縮數據刷新到下層io.Writer接口中。
本方法主要用在傳輸壓縮數據的網絡連接中,以保證遠端的接收者可以獲得足夠的數據來重構數據報。Flush會阻塞直到所有緩沖中的數據都寫入下層io.Writer接口后才返回。如果下層的io.Writetr接口返回一個錯誤,Flush也會返回該錯誤。在zlib包的術語中,Flush方法等價于Z_SYNC_FLUSH。
### func (\*Writer) [Close](https://github.com/golang/go/blob/master/src/compress/flate/deflate.go#L551 "View Source")
```
func (w *Writer) Close() error
```
Close刷新緩沖并關閉w。
- 庫
- package achive
- package tar
- package zip
- package bufio
- package builtin
- package bytes
- package compress
- package bzip2
- package flate
- package gzip
- package lzw
- package zlib
- package container
- package heap
- package list
- package ring
- package crypto
- package aes
- package cipher
- package des
- package dsa
- package ecdsa
- package elliptic
- package hmac
- package md5
- package rand
- package rc4
- package rsa
- package sha1
- package sha256
- package sha512
- package subtle
- package tls
- package x509
- package pkix
- package database
- package sql
- package driver
- package encoding
- package ascii85
- package asn1
- package base32
- package base64
- package binary
- package csv
- package gob
- package hex
- package json
- package pem
- package xml
- package errors
- package expvar
- package flag
- package fmt
- package go
- package doc
- package format
- package parser
- package printer
- package hash
- package adler32
- package crc32
- package crc64
- package fnv
- package html
- package template
- package image
- package color
- package palette
- package draw
- package gif
- package jpeg
- package png
- package index
- package suffixarray
- package io
- package ioutil
- package log
- package syslog
- package math
- package big
- package cmplx
- package rand
- package mime
- package multipart
- package net
- package http
- package cgi
- package cookiejar
- package fcgi
- package httptest
- package httputil
- package pprof
- package mail
- package rpc
- package jsonrpc
- package smtp
- package textproto
- package url
- package os
- package exec
- package signal
- package user
- package path
- package filepath
- package reflect
- package regexp
- package runtime
- package cgo
- package debug
- package pprof
- package race
- package sort
- package strconv
- package strings
- package sync
- package atomic
- package text
- package scanner
- package tabwriter
- package template
- package time
- package unicode
- package utf16
- package utf8
- package unsafe