# 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