ZipCompressor returns a compressor that can be registered with zip libraries. The provided encoder options will be used on all encodes.
(opts ...EOption)
| 115 | // ZipCompressor returns a compressor that can be registered with zip libraries. |
| 116 | // The provided encoder options will be used on all encodes. |
| 117 | func ZipCompressor(opts ...EOption) func(w io.Writer) (io.WriteCloser, error) { |
| 118 | var pool sync.Pool |
| 119 | return func(w io.Writer) (io.WriteCloser, error) { |
| 120 | enc, ok := pool.Get().(*Encoder) |
| 121 | if ok { |
| 122 | enc.Reset(w) |
| 123 | } else { |
| 124 | var err error |
| 125 | enc, err = NewWriter(w, opts...) |
| 126 | if err != nil { |
| 127 | return nil, err |
| 128 | } |
| 129 | } |
| 130 | return &pooledZipWriter{enc: enc, pool: &pool}, nil |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | // ZipDecompressor returns a decompressor that can be registered with zip libraries. |
| 135 | // See ZipCompressor for example. |
searching dependent graphs…