-
Notifications
You must be signed in to change notification settings - Fork 45
/
example_test.go
53 lines (48 loc) · 1.12 KB
/
example_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Copyright 2014-2022 Ulrich Kunitz. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package xz_test
import (
"bufio"
"fmt"
"io"
"log"
"os"
"github.com/ulikunitz/xz"
)
func ExampleReader() {
f, err := os.Open("fox.xz")
if err != nil {
log.Fatalf("os.Open(%q) error %s", "fox.xz", err)
}
defer f.Close()
r, err := xz.NewReader(bufio.NewReader(f))
if err != nil {
log.Fatalf("xz.NewReader(f) error %s", err)
}
if _, err = io.Copy(os.Stdout, r); err != nil {
log.Fatalf("io.Copy error %s", err)
}
// Output:
// The quick brown fox jumps over the lazy dog.
}
func ExampleWriter() {
f, err := os.Create("example.xz")
if err != nil {
log.Fatalf("os.Open(%q) error %s", "example.xz", err)
}
defer f.Close()
w, err := xz.NewWriter(f)
if err != nil {
log.Fatalf("xz.NewWriter(f) error %s", err)
}
defer w.Close()
_, err = fmt.Fprintln(w, "The brown fox jumps over the lazy dog.")
if err != nil {
log.Fatalf("fmt.Fprintln error %s", err)
}
if err = w.Close(); err != nil {
log.Fatalf("w.Close() error %s", err)
}
// Output:
}