Standard library / archive/zip

archive/zip.Writer.SetOffset()

Specify existing destination prefix length before writing any ZIP data, for archives appended to another file. Expected stdout: 'a.txt\n'.

Formal Syntax & Structure

go syntaxgo
func (w *Writer) SetOffset(n int64)

Parameters & Attributes

NameTypeDescription
nint64Offset of archive start within the destination.

Working Example

Example Snippetgo
package main
import (  "archive/zip"  "bytes"  "fmt")
func must(e error) {  if e != nil {    panic(e)  }}
func main() {  var b bytes.Buffer  b.WriteString("prefix")  w := zip.NewWriter(&b)  w.SetOffset(6)  f, e := w.Create("a.txt")  must(e)  _, e = f.Write([]byte("Go"))  must(e)  must(w.Close())  r, e := zip.NewReader(bytes.NewReader(b.Bytes()), int64(b.Len()))  must(e)  fmt.Println(r.File[0].Name)}
Go Reference