Standard library / archive/zip

archive/zip.Writer.Create()

Start a named ZIP file using Deflate; names should be relative slash-separated paths. Finish writing before creating another entry. Expected stdout: 'a.txt\n'.

Formal Syntax & Structure

go syntaxgo
func (w *Writer) Create(name string) (io.Writer, error)

Parameters & Attributes

NameTypeDescription
namestringArchive filename or slash-separated entry name, depending on operation.

Return Value

(io.Writer, error)

Entry writer or error; finish before creating another entry.

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  w := zip.NewWriter(&b)  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