Documentation
¶
Overview ¶
Package compress 提供压缩算法相关的功能
Index ¶
- Constants
- type Compresses
- func (e *Compresses) AcceptEncoding(contentType, h string, l logs.Logger) (w *NamedCompress, notAcceptable bool)
- func (e *Compresses) AcceptEncodingHeader() string
- func (e *Compresses) Add(name string, c Compressor, ct ...string) *Compresses
- func (e *Compresses) ContentEncoding(name string, r io.Reader) (io.ReadCloser, error)
- func (e *Compresses) IsDisable() bool
- func (e *Compresses) SetDisable(disable bool)
- type Compressor
- type NamedCompress
Constants ¶
View Source
const Identity = "identity"
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Compresses ¶
type Compresses struct {
// contains filtered or unexported fields
}
Compresses 压缩算法的管理
func NewCompresses ¶
func NewCompresses(cap int, disable bool) *Compresses
func (*Compresses) AcceptEncoding ¶
func (e *Compresses) AcceptEncoding(contentType, h string, l logs.Logger) (w *NamedCompress, notAcceptable bool)
AcceptEncoding 根据客户端的 Accept-Encoding 报头查找最合适的算法
如果返回的 w 为空值表示不需要压缩。 当有多个符合时,按添加顺序拿第一个符合条件数据。 l 表示解析报头过程中的错误信息,可以为空,表示不输出信息;
func (*Compresses) AcceptEncodingHeader ¶
func (e *Compresses) AcceptEncodingHeader() string
AcceptEncodingHeader 生成 AcceptEncoding 报头内容
func (*Compresses) Add ¶
func (e *Compresses) Add(name string, c Compressor, ct ...string) *Compresses
Add 添加新的压缩算法
func (*Compresses) ContentEncoding ¶
func (e *Compresses) ContentEncoding(name string, r io.Reader) (io.ReadCloser, error)
ContentEncoding 根据 Content-Encoding 报头返回相应的解码对象
name 编码名称,即 Content-Encoding 报头内容; r 为未解码的内容;
func (*Compresses) IsDisable ¶
func (e *Compresses) IsDisable() bool
func (*Compresses) SetDisable ¶
func (e *Compresses) SetDisable(disable bool)
type Compressor ¶
type Compressor interface {
// Decoder 将 r 包装成为当前压缩算法的解码器
Decoder(r io.Reader) (io.ReadCloser, error)
// Encoder 将 w 包装成当前压缩算法的编码器
Encoder(w io.Writer) (io.WriteCloser, error)
}
Compressor 压缩算法的接口
func NewBrotliCompress ¶
func NewBrotliCompress(o brotli.WriterOptions) Compressor
NewBrotliCompress 声明基于 br 的压缩算法
func NewDeflateCompress ¶
func NewDeflateCompress(level int, dict []byte) Compressor
NewDeflateCompress 声明基于 deflate 的压缩算法
func NewLZWCompress ¶
func NewLZWCompress(order lzw.Order, width int) Compressor
NewLZWCompress 声明基于 lzw 的压缩算法
NOTE: 在 http 报头中名称为 compress 或是 x-compress
type NamedCompress ¶
type NamedCompress struct {
// contains filtered or unexported fields
}
NamedCompress 带名称的压缩算法
Click to show internal directories.
Click to hide internal directories.