MCPcopy
hub / github.com/klauspost/compress / ExampleWriter

Function ExampleWriter

zip/example_test.go:18–49  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16)
17
18func ExampleWriter() {
19 // Create a buffer to write our archive to.
20 buf := new(bytes.Buffer)
21
22 // Create a new zip archive.
23 w := zip.NewWriter(buf)
24
25 // Add some files to the archive.
26 var files = []struct {
27 Name, Body string
28 }{
29 {"readme.txt", "This archive contains some text files."},
30 {"gopher.txt", "Gopher names:\nGeorge\nGeoffrey\nGonzo"},
31 {"todo.txt", "Get animal handling licence.\nWrite more examples."},
32 }
33 for _, file := range files {
34 f, err := w.Create(file.Name)
35 if err != nil {
36 log.Fatal(err)
37 }
38 _, err = f.Write([]byte(file.Body))
39 if err != nil {
40 log.Fatal(err)
41 }
42 }
43
44 // Make sure to check the error on Close.
45 err := w.Close()
46 if err != nil {
47 log.Fatal(err)
48 }
49}
50
51func ExampleReader() {
52 // Open a zip archive for reading.

Callers

nothing calls this directly

Calls 5

CreateMethod · 0.95
CloseMethod · 0.95
NewWriterFunction · 0.92
FatalMethod · 0.80
WriteMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…