summaryrefslogtreecommitdiff
path: root/devdocs/go/archive%2Fzip%2Findex.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/go/archive%2Fzip%2Findex.html
new repository
Diffstat (limited to 'devdocs/go/archive%2Fzip%2Findex.html')
-rw-r--r--devdocs/go/archive%2Fzip%2Findex.html290
1 files changed, 290 insertions, 0 deletions
diff --git a/devdocs/go/archive%2Fzip%2Findex.html b/devdocs/go/archive%2Fzip%2Findex.html
new file mode 100644
index 00000000..18031762
--- /dev/null
+++ b/devdocs/go/archive%2Fzip%2Findex.html
@@ -0,0 +1,290 @@
+<h1> Package zip </h1> <ul id="short-nav">
+<li><code>import "archive/zip"</code></li>
+<li><a href="#pkg-overview" class="overviewLink">Overview</a></li>
+<li><a href="#pkg-index" class="indexLink">Index</a></li>
+<li><a href="#pkg-examples" class="examplesLink">Examples</a></li>
+</ul> <h2 id="pkg-overview">Overview </h2> <p>Package zip provides support for reading and writing ZIP archives. </p>
+<p>See the <a href="https://support.pkware.com/pkzip/appnote">ZIP specification</a> for details. </p>
+<p>This package does not support disk spanning. </p>
+<p>A note about ZIP64: </p>
+<p>To be backwards compatible the FileHeader has both 32 and 64 bit Size fields. The 64 bit fields will always contain the correct value and for normal archives both fields will be the same. For files requiring the ZIP64 format the 32 bit fields will be 0xffffffff and the 64 bit fields must be used instead. </p> <h2 id="pkg-index">Index </h2> <ul id="manual-nav">
+<li><a href="#pkg-constants">Constants</a></li>
+<li><a href="#pkg-variables">Variables</a></li>
+<li><a href="#RegisterCompressor">func RegisterCompressor(method uint16, comp Compressor)</a></li>
+<li><a href="#RegisterDecompressor">func RegisterDecompressor(method uint16, dcomp Decompressor)</a></li>
+<li><a href="#Compressor">type Compressor</a></li>
+<li><a href="#Decompressor">type Decompressor</a></li>
+<li><a href="#File">type File</a></li>
+<li> <a href="#File.DataOffset">func (f *File) DataOffset() (offset int64, err error)</a>
+</li>
+<li> <a href="#File.Open">func (f *File) Open() (io.ReadCloser, error)</a>
+</li>
+<li> <a href="#File.OpenRaw">func (f *File) OpenRaw() (io.Reader, error)</a>
+</li>
+<li><a href="#FileHeader">type FileHeader</a></li>
+<li> <a href="#FileInfoHeader">func FileInfoHeader(fi fs.FileInfo) (*FileHeader, error)</a>
+</li>
+<li> <a href="#FileHeader.FileInfo">func (h *FileHeader) FileInfo() fs.FileInfo</a>
+</li>
+<li> <a href="#FileHeader.ModTime">func (h *FileHeader) ModTime() time.Time</a>
+</li>
+<li> <a href="#FileHeader.Mode">func (h *FileHeader) Mode() (mode fs.FileMode)</a>
+</li>
+<li> <a href="#FileHeader.SetModTime">func (h *FileHeader) SetModTime(t time.Time)</a>
+</li>
+<li> <a href="#FileHeader.SetMode">func (h *FileHeader) SetMode(mode fs.FileMode)</a>
+</li>
+<li><a href="#ReadCloser">type ReadCloser</a></li>
+<li> <a href="#OpenReader">func OpenReader(name string) (*ReadCloser, error)</a>
+</li>
+<li> <a href="#ReadCloser.Close">func (rc *ReadCloser) Close() error</a>
+</li>
+<li><a href="#Reader">type Reader</a></li>
+<li> <a href="#NewReader">func NewReader(r io.ReaderAt, size int64) (*Reader, error)</a>
+</li>
+<li> <a href="#Reader.Open">func (r *Reader) Open(name string) (fs.File, error)</a>
+</li>
+<li> <a href="#Reader.RegisterDecompressor">func (r *Reader) RegisterDecompressor(method uint16, dcomp Decompressor)</a>
+</li>
+<li><a href="#Writer">type Writer</a></li>
+<li> <a href="#NewWriter">func NewWriter(w io.Writer) *Writer</a>
+</li>
+<li> <a href="#Writer.AddFS">func (w *Writer) AddFS(fsys fs.FS) error</a>
+</li>
+<li> <a href="#Writer.Close">func (w *Writer) Close() error</a>
+</li>
+<li> <a href="#Writer.Copy">func (w *Writer) Copy(f *File) error</a>
+</li>
+<li> <a href="#Writer.Create">func (w *Writer) Create(name string) (io.Writer, error)</a>
+</li>
+<li> <a href="#Writer.CreateHeader">func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)</a>
+</li>
+<li> <a href="#Writer.CreateRaw">func (w *Writer) CreateRaw(fh *FileHeader) (io.Writer, error)</a>
+</li>
+<li> <a href="#Writer.Flush">func (w *Writer) Flush() error</a>
+</li>
+<li> <a href="#Writer.RegisterCompressor">func (w *Writer) RegisterCompressor(method uint16, comp Compressor)</a>
+</li>
+<li> <a href="#Writer.SetComment">func (w *Writer) SetComment(comment string) error</a>
+</li>
+<li> <a href="#Writer.SetOffset">func (w *Writer) SetOffset(n int64)</a>
+</li>
+</ul> <div id="pkg-examples"> <h3>Examples</h3> <dl> <dd><a class="exampleLink" href="#example_Reader">Reader</a></dd> <dd><a class="exampleLink" href="#example_Writer">Writer</a></dd> <dd><a class="exampleLink" href="#example_Writer_RegisterCompressor">Writer.RegisterCompressor</a></dd> </dl> </div> <h3>Package files</h3> <p> <span>reader.go</span> <span>register.go</span> <span>struct.go</span> <span>writer.go</span> </p> <h2 id="pkg-constants">Constants</h2> <p>Compression methods. </p>
+<pre data-language="go">const (
+ Store uint16 = 0 // no compression
+ Deflate uint16 = 8 // DEFLATE compressed
+)</pre> <h2 id="pkg-variables">Variables</h2> <pre data-language="go">var (
+ ErrFormat = errors.New("zip: not a valid zip file")
+ ErrAlgorithm = errors.New("zip: unsupported compression algorithm")
+ ErrChecksum = errors.New("zip: checksum error")
+ ErrInsecurePath = errors.New("zip: insecure file path")
+)</pre> <h2 id="RegisterCompressor">func <span>RegisterCompressor</span> <span title="Added in Go 1.2">1.2</span> </h2> <pre data-language="go">func RegisterCompressor(method uint16, comp Compressor)</pre> <p>RegisterCompressor registers custom compressors for a specified method ID. The common methods <a href="#Store">Store</a> and <a href="#Deflate">Deflate</a> are built in. </p>
+<h2 id="RegisterDecompressor">func <span>RegisterDecompressor</span> <span title="Added in Go 1.2">1.2</span> </h2> <pre data-language="go">func RegisterDecompressor(method uint16, dcomp Decompressor)</pre> <p>RegisterDecompressor allows custom decompressors for a specified method ID. The common methods <a href="#Store">Store</a> and <a href="#Deflate">Deflate</a> are built in. </p>
+<h2 id="Compressor">type <span>Compressor</span> <span title="Added in Go 1.2">1.2</span> </h2> <p>A Compressor returns a new compressing writer, writing to w. The WriteCloser's Close method must be used to flush pending data to w. The Compressor itself must be safe to invoke from multiple goroutines simultaneously, but each returned writer will be used only by one goroutine at a time. </p>
+<pre data-language="go">type Compressor func(w io.Writer) (io.WriteCloser, error)</pre> <h2 id="Decompressor">type <span>Decompressor</span> <span title="Added in Go 1.2">1.2</span> </h2> <p>A Decompressor returns a new decompressing reader, reading from r. The <span>io.ReadCloser</span>'s Close method must be used to release associated resources. The Decompressor itself must be safe to invoke from multiple goroutines simultaneously, but each returned reader will be used only by one goroutine at a time. </p>
+<pre data-language="go">type Decompressor func(r io.Reader) io.ReadCloser</pre> <h2 id="File">type <span>File</span> </h2> <p>A File is a single file in a ZIP archive. The file information is in the embedded <a href="#FileHeader">FileHeader</a>. The file content can be accessed by calling <a href="#File.Open">File.Open</a>. </p>
+<pre data-language="go">type File struct {
+ FileHeader
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="File.DataOffset">func (*File) <span>DataOffset</span> <span title="Added in Go 1.2">1.2</span> </h3> <pre data-language="go">func (f *File) DataOffset() (offset int64, err error)</pre> <p>DataOffset returns the offset of the file's possibly-compressed data, relative to the beginning of the zip file. </p>
+<p>Most callers should instead use <a href="#File.Open">File.Open</a>, which transparently decompresses data and verifies checksums. </p>
+<h3 id="File.Open">func (*File) <span>Open</span> </h3> <pre data-language="go">func (f *File) Open() (io.ReadCloser, error)</pre> <p>Open returns a <a href="#ReadCloser">ReadCloser</a> that provides access to the <a href="#File">File</a>'s contents. Multiple files may be read concurrently. </p>
+<h3 id="File.OpenRaw">func (*File) <span>OpenRaw</span> <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func (f *File) OpenRaw() (io.Reader, error)</pre> <p>OpenRaw returns a <a href="#Reader">Reader</a> that provides access to the <a href="#File">File</a>'s contents without decompression. </p>
+<h2 id="FileHeader">type <span>FileHeader</span> </h2> <p>FileHeader describes a file within a ZIP file. See the <a href="https://support.pkware.com/pkzip/appnote">ZIP specification</a> for details. </p>
+<pre data-language="go">type FileHeader struct {
+ // Name is the name of the file.
+ //
+ // It must be a relative path, not start with a drive letter (such as "C:"),
+ // and must use forward slashes instead of back slashes. A trailing slash
+ // indicates that this file is a directory and should have no data.
+ Name string
+
+ // Comment is any arbitrary user-defined string shorter than 64KiB.
+ Comment string
+
+ // NonUTF8 indicates that Name and Comment are not encoded in UTF-8.
+ //
+ // By specification, the only other encoding permitted should be CP-437,
+ // but historically many ZIP readers interpret Name and Comment as whatever
+ // the system's local character encoding happens to be.
+ //
+ // This flag should only be set if the user intends to encode a non-portable
+ // ZIP file for a specific localized region. Otherwise, the Writer
+ // automatically sets the ZIP format's UTF-8 flag for valid UTF-8 strings.
+ NonUTF8 bool // Go 1.10
+
+ CreatorVersion uint16
+ ReaderVersion uint16
+ Flags uint16
+
+ // Method is the compression method. If zero, Store is used.
+ Method uint16
+
+ // Modified is the modified time of the file.
+ //
+ // When reading, an extended timestamp is preferred over the legacy MS-DOS
+ // date field, and the offset between the times is used as the timezone.
+ // If only the MS-DOS date is present, the timezone is assumed to be UTC.
+ //
+ // When writing, an extended timestamp (which is timezone-agnostic) is
+ // always emitted. The legacy MS-DOS date field is encoded according to the
+ // location of the Modified time.
+ Modified time.Time // Go 1.10
+
+ // ModifiedTime is an MS-DOS-encoded time.
+ //
+ // Deprecated: Use Modified instead.
+ ModifiedTime uint16
+
+ // ModifiedDate is an MS-DOS-encoded date.
+ //
+ // Deprecated: Use Modified instead.
+ ModifiedDate uint16
+
+ // CRC32 is the CRC32 checksum of the file content.
+ CRC32 uint32
+
+ // CompressedSize is the compressed size of the file in bytes.
+ // If either the uncompressed or compressed size of the file
+ // does not fit in 32 bits, CompressedSize is set to ^uint32(0).
+ //
+ // Deprecated: Use CompressedSize64 instead.
+ CompressedSize uint32
+
+ // UncompressedSize is the compressed size of the file in bytes.
+ // If either the uncompressed or compressed size of the file
+ // does not fit in 32 bits, CompressedSize is set to ^uint32(0).
+ //
+ // Deprecated: Use UncompressedSize64 instead.
+ UncompressedSize uint32
+
+ // CompressedSize64 is the compressed size of the file in bytes.
+ CompressedSize64 uint64 // Go 1.1
+
+ // UncompressedSize64 is the uncompressed size of the file in bytes.
+ UncompressedSize64 uint64 // Go 1.1
+
+ Extra []byte
+ ExternalAttrs uint32 // Meaning depends on CreatorVersion
+}
+</pre> <h3 id="FileInfoHeader">func <span>FileInfoHeader</span> </h3> <pre data-language="go">func FileInfoHeader(fi fs.FileInfo) (*FileHeader, error)</pre> <p>FileInfoHeader creates a partially-populated <a href="#FileHeader">FileHeader</a> from an fs.FileInfo. Because fs.FileInfo's Name method returns only the base name of the file it describes, it may be necessary to modify the Name field of the returned header to provide the full path name of the file. If compression is desired, callers should set the FileHeader.Method field; it is unset by default. </p>
+<h3 id="FileHeader.FileInfo">func (*FileHeader) <span>FileInfo</span> </h3> <pre data-language="go">func (h *FileHeader) FileInfo() fs.FileInfo</pre> <p>FileInfo returns an fs.FileInfo for the <a href="#FileHeader">FileHeader</a>. </p>
+<h3 id="FileHeader.ModTime">func (*FileHeader) <span>ModTime</span> </h3> <pre data-language="go">func (h *FileHeader) ModTime() time.Time</pre> <p>ModTime returns the modification time in UTC using the legacy [ModifiedDate] and [ModifiedTime] fields. </p>
+<p>Deprecated: Use [Modified] instead. </p>
+<h3 id="FileHeader.Mode">func (*FileHeader) <span>Mode</span> </h3> <pre data-language="go">func (h *FileHeader) Mode() (mode fs.FileMode)</pre> <p>Mode returns the permission and mode bits for the <a href="#FileHeader">FileHeader</a>. </p>
+<h3 id="FileHeader.SetModTime">func (*FileHeader) <span>SetModTime</span> </h3> <pre data-language="go">func (h *FileHeader) SetModTime(t time.Time)</pre> <p>SetModTime sets the [Modified], [ModifiedTime], and [ModifiedDate] fields to the given time in UTC. </p>
+<p>Deprecated: Use [Modified] instead. </p>
+<h3 id="FileHeader.SetMode">func (*FileHeader) <span>SetMode</span> </h3> <pre data-language="go">func (h *FileHeader) SetMode(mode fs.FileMode)</pre> <p>SetMode changes the permission and mode bits for the <a href="#FileHeader">FileHeader</a>. </p>
+<h2 id="ReadCloser">type <span>ReadCloser</span> </h2> <p>A ReadCloser is a <a href="#Reader">Reader</a> that must be closed when no longer needed. </p>
+<pre data-language="go">type ReadCloser struct {
+ Reader
+ // contains filtered or unexported fields
+}
+</pre> <h3 id="OpenReader">func <span>OpenReader</span> </h3> <pre data-language="go">func OpenReader(name string) (*ReadCloser, error)</pre> <p>OpenReader will open the Zip file specified by name and return a ReadCloser. </p>
+<p>If any file inside the archive uses a non-local name (as defined by <span>filepath.IsLocal</span>) or a name containing backslashes and the GODEBUG environment variable contains `zipinsecurepath=0`, OpenReader returns the reader with an ErrInsecurePath error. A future version of Go may introduce this behavior by default. Programs that want to accept non-local names can ignore the ErrInsecurePath error and use the returned reader. </p>
+<h3 id="ReadCloser.Close">func (*ReadCloser) <span>Close</span> </h3> <pre data-language="go">func (rc *ReadCloser) Close() error</pre> <p>Close closes the Zip file, rendering it unusable for I/O. </p>
+<h2 id="Reader">type <span>Reader</span> </h2> <p>A Reader serves content from a ZIP archive. </p>
+<pre data-language="go">type Reader struct {
+ File []*File
+ Comment string
+ // contains filtered or unexported fields
+}
+</pre> <h4 id="example_Reader"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">// Open a zip archive for reading.
+r, err := zip.OpenReader("testdata/readme.zip")
+if err != nil {
+ log.Fatal(err)
+}
+defer r.Close()
+
+// Iterate through the files in the archive,
+// printing some of their contents.
+for _, f := range r.File {
+ fmt.Printf("Contents of %s:\n", f.Name)
+ rc, err := f.Open()
+ if err != nil {
+ log.Fatal(err)
+ }
+ _, err = io.CopyN(os.Stdout, rc, 68)
+ if err != nil {
+ log.Fatal(err)
+ }
+ rc.Close()
+ fmt.Println()
+}
+</pre> <p>Output:</p> <pre class="output" data-language="go">Contents of README:
+This is the source code repository for the Go programming language.
+</pre> <h3 id="NewReader">func <span>NewReader</span> </h3> <pre data-language="go">func NewReader(r io.ReaderAt, size int64) (*Reader, error)</pre> <p>NewReader returns a new <a href="#Reader">Reader</a> reading from r, which is assumed to have the given size in bytes. </p>
+<p>If any file inside the archive uses a non-local name (as defined by <span>filepath.IsLocal</span>) or a name containing backslashes and the GODEBUG environment variable contains `zipinsecurepath=0`, NewReader returns the reader with an <a href="#ErrInsecurePath">ErrInsecurePath</a> error. A future version of Go may introduce this behavior by default. Programs that want to accept non-local names can ignore the <a href="#ErrInsecurePath">ErrInsecurePath</a> error and use the returned reader. </p>
+<h3 id="Reader.Open">func (*Reader) <span>Open</span> <span title="Added in Go 1.16">1.16</span> </h3> <pre data-language="go">func (r *Reader) Open(name string) (fs.File, error)</pre> <p>Open opens the named file in the ZIP archive, using the semantics of fs.FS.Open: paths are always slash separated, with no leading / or ../ elements. </p>
+<h3 id="Reader.RegisterDecompressor">func (*Reader) <span>RegisterDecompressor</span> <span title="Added in Go 1.6">1.6</span> </h3> <pre data-language="go">func (r *Reader) RegisterDecompressor(method uint16, dcomp Decompressor)</pre> <p>RegisterDecompressor registers or overrides a custom decompressor for a specific method ID. If a decompressor for a given method is not found, <a href="#Reader">Reader</a> will default to looking up the decompressor at the package level. </p>
+<h2 id="Writer">type <span>Writer</span> </h2> <p>Writer implements a zip file writer. </p>
+<pre data-language="go">type Writer struct {
+ // contains filtered or unexported fields
+}
+</pre> <h4 id="example_Writer"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+// Create a buffer to write our archive to.
+buf := new(bytes.Buffer)
+
+// Create a new zip archive.
+w := zip.NewWriter(buf)
+
+// Add some files to the archive.
+var files = []struct {
+ Name, Body string
+}{
+ {"readme.txt", "This archive contains some text files."},
+ {"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
+ {"todo.txt", "Get animal handling licence.\nWrite more examples."},
+}
+for _, file := range files {
+ f, err := w.Create(file.Name)
+ if err != nil {
+ log.Fatal(err)
+ }
+ _, err = f.Write([]byte(file.Body))
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+// Make sure to check the error on Close.
+err := w.Close()
+if err != nil {
+ log.Fatal(err)
+}
+</pre> <h3 id="NewWriter">func <span>NewWriter</span> </h3> <pre data-language="go">func NewWriter(w io.Writer) *Writer</pre> <p>NewWriter returns a new <a href="#Writer">Writer</a> writing a zip file to w. </p>
+<h3 id="Writer.AddFS">func (*Writer) <span>AddFS</span> <span title="Added in Go 1.22">1.22</span> </h3> <pre data-language="go">func (w *Writer) AddFS(fsys fs.FS) error</pre> <p>AddFS adds the files from fs.FS to the archive. It walks the directory tree starting at the root of the filesystem adding each file to the zip using deflate while maintaining the directory structure. </p>
+<h3 id="Writer.Close">func (*Writer) <span>Close</span> </h3> <pre data-language="go">func (w *Writer) Close() error</pre> <p>Close finishes writing the zip file by writing the central directory. It does not close the underlying writer. </p>
+<h3 id="Writer.Copy">func (*Writer) <span>Copy</span> <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func (w *Writer) Copy(f *File) error</pre> <p>Copy copies the file f (obtained from a <a href="#Reader">Reader</a>) into w. It copies the raw form directly bypassing decompression, compression, and validation. </p>
+<h3 id="Writer.Create">func (*Writer) <span>Create</span> </h3> <pre data-language="go">func (w *Writer) Create(name string) (io.Writer, error)</pre> <p>Create adds a file to the zip file using the provided name. It returns a <a href="#Writer">Writer</a> to which the file contents should be written. The file contents will be compressed using the <a href="#Deflate">Deflate</a> method. The name must be a relative path: it must not start with a drive letter (e.g. C:) or leading slash, and only forward slashes are allowed. To create a directory instead of a file, add a trailing slash to the name. The file's contents must be written to the <span>io.Writer</span> before the next call to <a href="#Writer.Create">Writer.Create</a>, <a href="#Writer.CreateHeader">Writer.CreateHeader</a>, or <a href="#Writer.Close">Writer.Close</a>. </p>
+<h3 id="Writer.CreateHeader">func (*Writer) <span>CreateHeader</span> </h3> <pre data-language="go">func (w *Writer) CreateHeader(fh *FileHeader) (io.Writer, error)</pre> <p>CreateHeader adds a file to the zip archive using the provided <a href="#FileHeader">FileHeader</a> for the file metadata. <a href="#Writer">Writer</a> takes ownership of fh and may mutate its fields. The caller must not modify fh after calling <a href="#Writer.CreateHeader">Writer.CreateHeader</a>. </p>
+<p>This returns a <a href="#Writer">Writer</a> to which the file contents should be written. The file's contents must be written to the io.Writer before the next call to <a href="#Writer.Create">Writer.Create</a>, <a href="#Writer.CreateHeader">Writer.CreateHeader</a>, <a href="#Writer.CreateRaw">Writer.CreateRaw</a>, or <a href="#Writer.Close">Writer.Close</a>. </p>
+<h3 id="Writer.CreateRaw">func (*Writer) <span>CreateRaw</span> <span title="Added in Go 1.17">1.17</span> </h3> <pre data-language="go">func (w *Writer) CreateRaw(fh *FileHeader) (io.Writer, error)</pre> <p>CreateRaw adds a file to the zip archive using the provided <a href="#FileHeader">FileHeader</a> and returns a <a href="#Writer">Writer</a> to which the file contents should be written. The file's contents must be written to the io.Writer before the next call to <a href="#Writer.Create">Writer.Create</a>, <a href="#Writer.CreateHeader">Writer.CreateHeader</a>, <a href="#Writer.CreateRaw">Writer.CreateRaw</a>, or <a href="#Writer.Close">Writer.Close</a>. </p>
+<p>In contrast to <a href="#Writer.CreateHeader">Writer.CreateHeader</a>, the bytes passed to Writer are not compressed. </p>
+<h3 id="Writer.Flush">func (*Writer) <span>Flush</span> <span title="Added in Go 1.4">1.4</span> </h3> <pre data-language="go">func (w *Writer) Flush() error</pre> <p>Flush flushes any buffered data to the underlying writer. Calling Flush is not normally necessary; calling Close is sufficient. </p>
+<h3 id="Writer.RegisterCompressor">func (*Writer) <span>RegisterCompressor</span> <span title="Added in Go 1.6">1.6</span> </h3> <pre data-language="go">func (w *Writer) RegisterCompressor(method uint16, comp Compressor)</pre> <p>RegisterCompressor registers or overrides a custom compressor for a specific method ID. If a compressor for a given method is not found, <a href="#Writer">Writer</a> will default to looking up the compressor at the package level. </p> <h4 id="example_Writer_RegisterCompressor"> <span class="text">Example</span>
+</h4> <p>Code:</p> <pre class="code" data-language="go">
+// Override the default Deflate compressor with a higher compression level.
+
+// Create a buffer to write our archive to.
+buf := new(bytes.Buffer)
+
+// Create a new zip archive.
+w := zip.NewWriter(buf)
+
+// Register a custom Deflate compressor.
+w.RegisterCompressor(zip.Deflate, func(out io.Writer) (io.WriteCloser, error) {
+ return flate.NewWriter(out, flate.BestCompression)
+})
+
+// Proceed to add files to w.
+</pre> <h3 id="Writer.SetComment">func (*Writer) <span>SetComment</span> <span title="Added in Go 1.10">1.10</span> </h3> <pre data-language="go">func (w *Writer) SetComment(comment string) error</pre> <p>SetComment sets the end-of-central-directory comment field. It can only be called before <a href="#Writer.Close">Writer.Close</a>. </p>
+<h3 id="Writer.SetOffset">func (*Writer) <span>SetOffset</span> <span title="Added in Go 1.5">1.5</span> </h3> <pre data-language="go">func (w *Writer) SetOffset(n int64)</pre> <p>SetOffset sets the offset of the beginning of the zip data within the underlying writer. It should be used when the zip data is appended to an existing file, such as a binary executable. It must be called before any data is written. </p><div class="_attribution">
+ <p class="_attribution-p">
+ &copy; Google, Inc.<br>Licensed under the Creative Commons Attribution License 3.0.<br>
+ <a href="http://golang.org/pkg/archive/zip/" class="_attribution-link">http://golang.org/pkg/archive/zip/</a>
+ </p>
+</div>