]> Cypherpunks repositories - gostls13.git/commitdiff
archive/zip: hide Write method from *Writer type
authorAndrew Gerrand <adg@golang.org>
Mon, 13 Feb 2012 23:47:48 +0000 (10:47 +1100)
committerAndrew Gerrand <adg@golang.org>
Mon, 13 Feb 2012 23:47:48 +0000 (10:47 +1100)
This was an implementation detail that snuck into the public interface.
*Writer.Create gives you an io.Writer, the *Writer itself was never
meant to be written to.

R=golang-dev, dsymonds, r
CC=golang-dev
https://golang.org/cl/5654076

doc/go1.html
doc/go1.tmpl
src/pkg/archive/zip/writer.go

index 0cf0c0a8def49ed899933c1103bda3fa7641b400..da31b91408200a7732f8a0932571ead030cb0104 100644 (file)
@@ -855,6 +855,18 @@ few programs beyond the need to run <code>go fix</code>.
 This category includes packages that are new in Go 1.
 </p>
 
+<h3 id="archive_zip">The archive/zip package</h3>
+
+<p>
+In Go 1, <a href="/pkg/archive/zip/#Writer"><code>*zip.Writer</code></a> no
+longer has a <code>Write</code> method. Its presence was a mistake.
+</p>
+
+<p>
+<i>Updating:</i> What little code is affected will be caught by the compiler
+and must be updated by hand. Such code is almost certainly incorrect.
+</p>
+
 <h3 id="crypto_aes_des">The crypto/aes and crypto/des packages</h3>
 
 <p>
index 5f6103beb9ec1d078f6d635d01baa976f85d9bac..1ef408813e41986d501954a659a3baffb73100ce 100644 (file)
@@ -759,6 +759,18 @@ few programs beyond the need to run <code>go fix</code>.
 This category includes packages that are new in Go 1.
 </p>
 
+<h3 id="archive_zip">The archive/zip package</h3>
+
+<p>
+In Go 1, <a href="/pkg/archive/zip/#Writer"><code>*zip.Writer</code></a> no
+longer has a <code>Write</code> method. Its presence was a mistake.
+</p>
+
+<p>
+<i>Updating:</i> What little code is affected will be caught by the compiler
+and must be updated by hand. Such code is almost certainly incorrect.
+</p>
+
 <h3 id="crypto_aes_des">The crypto/aes and crypto/des packages</h3>
 
 <p>
index 51e4f153672982e27e7b2ea89caa917a5391717a..c591aed5cedcc8fcef2e4dd08420aee24fac27c2 100644 (file)
@@ -19,7 +19,7 @@ import (
 
 // Writer implements a zip file writer.
 type Writer struct {
-       countWriter
+       cw     *countWriter
        dir    []*header
        last   *fileWriter
        closed bool
@@ -32,7 +32,7 @@ type header struct {
 
 // NewWriter returns a new Writer writing a zip file to w.
 func NewWriter(w io.Writer) *Writer {
-       return &Writer{countWriter: countWriter{w: bufio.NewWriter(w)}}
+       return &Writer{cw: &countWriter{w: bufio.NewWriter(w)}}
 }
 
 // Close finishes writing the zip file by writing the central directory.
@@ -52,42 +52,42 @@ func (w *Writer) Close() (err error) {
        defer recoverError(&err)
 
        // write central directory
-       start := w.count
+       start := w.cw.count
        for _, h := range w.dir {
-               write(w, uint32(directoryHeaderSignature))
-               write(w, h.CreatorVersion)
-               write(w, h.ReaderVersion)
-               write(w, h.Flags)
-               write(w, h.Method)
-               write(w, h.ModifiedTime)
-               write(w, h.ModifiedDate)
-               write(w, h.CRC32)
-               write(w, h.CompressedSize)
-               write(w, h.UncompressedSize)
-               write(w, uint16(len(h.Name)))
-               write(w, uint16(len(h.Extra)))
-               write(w, uint16(len(h.Comment)))
-               write(w, uint16(0)) // disk number start
-               write(w, uint16(0)) // internal file attributes
-               write(w, h.ExternalAttrs)
-               write(w, h.offset)
-               writeBytes(w, []byte(h.Name))
-               writeBytes(w, h.Extra)
-               writeBytes(w, []byte(h.Comment))
+               write(w.cw, uint32(directoryHeaderSignature))
+               write(w.cw, h.CreatorVersion)
+               write(w.cw, h.ReaderVersion)
+               write(w.cw, h.Flags)
+               write(w.cw, h.Method)
+               write(w.cw, h.ModifiedTime)
+               write(w.cw, h.ModifiedDate)
+               write(w.cw, h.CRC32)
+               write(w.cw, h.CompressedSize)
+               write(w.cw, h.UncompressedSize)
+               write(w.cw, uint16(len(h.Name)))
+               write(w.cw, uint16(len(h.Extra)))
+               write(w.cw, uint16(len(h.Comment)))
+               write(w.cw, uint16(0)) // disk number start
+               write(w.cw, uint16(0)) // internal file attributes
+               write(w.cw, h.ExternalAttrs)
+               write(w.cw, h.offset)
+               writeBytes(w.cw, []byte(h.Name))
+               writeBytes(w.cw, h.Extra)
+               writeBytes(w.cw, []byte(h.Comment))
        }
-       end := w.count
+       end := w.cw.count
 
        // write end record
-       write(w, uint32(directoryEndSignature))
-       write(w, uint16(0))          // disk number
-       write(w, uint16(0))          // disk number where directory starts
-       write(w, uint16(len(w.dir))) // number of entries this disk
-       write(w, uint16(len(w.dir))) // number of entries total
-       write(w, uint32(end-start))  // size of directory
-       write(w, uint32(start))      // start of directory
-       write(w, uint16(0))          // size of comment
+       write(w.cw, uint32(directoryEndSignature))
+       write(w.cw, uint16(0))          // disk number
+       write(w.cw, uint16(0))          // disk number where directory starts
+       write(w.cw, uint16(len(w.dir))) // number of entries this disk
+       write(w.cw, uint16(len(w.dir))) // number of entries total
+       write(w.cw, uint32(end-start))  // size of directory
+       write(w.cw, uint32(start))      // start of directory
+       write(w.cw, uint16(0))          // size of comment
 
-       return w.w.(*bufio.Writer).Flush()
+       return w.cw.w.(*bufio.Writer).Flush()
 }
 
 // Create adds a file to the zip file using the provided name.
@@ -119,8 +119,8 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
        fh.ReaderVersion = 0x14
 
        fw := &fileWriter{
-               zipw:      w,
-               compCount: &countWriter{w: w},
+               zipw:      w.cw,
+               compCount: &countWriter{w: w.cw},
                crc32:     crc32.NewIEEE(),
        }
        switch fh.Method {
@@ -139,12 +139,12 @@ func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error) {
 
        h := &header{
                FileHeader: fh,
-               offset:     uint32(w.count),
+               offset:     uint32(w.cw.count),
        }
        w.dir = append(w.dir, h)
        fw.header = h
 
-       if err := writeHeader(w, fh); err != nil {
+       if err := writeHeader(w.cw, fh); err != nil {
                return nil, err
        }