~ubuntu-branches/ubuntu/vivid/golang/vivid

« back to all changes in this revision

Viewing changes to src/pkg/archive/zip/register.go

  • Committer: Package Import Robot
  • Author(s): Serge Hallyn
  • Date: 2014-11-18 15:12:26 UTC
  • mfrom: (14.2.12 vivid-proposed)
  • Revision ID: package-import@ubuntu.com-20141118151226-zug7vn93mn3dtiz3
Tags: 2:1.3.2-1ubuntu1
* Merge from Debian unstable.  Remaining changes:
  - 016-armhf-elf-header.patch: Use correct ELF header for armhf binaries.
  - Support co-installability with gccgo-go tool:
    - d/rules,golang-go.install: Rename bin/go -> bin/golang-go
    - d/golang-go.{postinst,prerm}: Install/remove /usr/bin/go using
      alternatives.
  - d/copyright: Amendments for full compiliance with copyright format.
  - d/control: Demote golang-go.tools to Suggests to support Ubuntu MIR.
  - dropped patches (now upstream):
    - d/p/issue27650045_40001_50001.diff
    - d/p/issue28050043_60001_70001.diff
    - d/p/issue54790044_100001_110001.diff

Show diffs side-by-side

added added

removed removed

Lines of Context:
6
6
 
7
7
import (
8
8
        "compress/flate"
 
9
        "errors"
9
10
        "io"
10
11
        "io/ioutil"
11
12
        "sync"
21
22
// when they're finished reading.
22
23
type Decompressor func(io.Reader) io.ReadCloser
23
24
 
 
25
var flateWriterPool sync.Pool
 
26
 
 
27
func newFlateWriter(w io.Writer) io.WriteCloser {
 
28
        fw, ok := flateWriterPool.Get().(*flate.Writer)
 
29
        if ok {
 
30
                fw.Reset(w)
 
31
        } else {
 
32
                fw, _ = flate.NewWriter(w, 5)
 
33
        }
 
34
        return &pooledFlateWriter{fw: fw}
 
35
}
 
36
 
 
37
type pooledFlateWriter struct {
 
38
        mu sync.Mutex // guards Close and Write
 
39
        fw *flate.Writer
 
40
}
 
41
 
 
42
func (w *pooledFlateWriter) Write(p []byte) (n int, err error) {
 
43
        w.mu.Lock()
 
44
        defer w.mu.Unlock()
 
45
        if w.fw == nil {
 
46
                return 0, errors.New("Write after Close")
 
47
        }
 
48
        return w.fw.Write(p)
 
49
}
 
50
 
 
51
func (w *pooledFlateWriter) Close() error {
 
52
        w.mu.Lock()
 
53
        defer w.mu.Unlock()
 
54
        var err error
 
55
        if w.fw != nil {
 
56
                err = w.fw.Close()
 
57
                flateWriterPool.Put(w.fw)
 
58
                w.fw = nil
 
59
        }
 
60
        return err
 
61
}
 
62
 
24
63
var (
25
64
        mu sync.RWMutex // guards compressor and decompressor maps
26
65
 
27
66
        compressors = map[uint16]Compressor{
28
67
                Store:   func(w io.Writer) (io.WriteCloser, error) { return &nopCloser{w}, nil },
29
 
                Deflate: func(w io.Writer) (io.WriteCloser, error) { return flate.NewWriter(w, 5) },
 
68
                Deflate: func(w io.Writer) (io.WriteCloser, error) { return newFlateWriter(w), nil },
30
69
        }
31
70
 
32
71
        decompressors = map[uint16]Decompressor{