-
Notifications
You must be signed in to change notification settings - Fork 0
/
example_test.go
89 lines (66 loc) · 1.42 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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// SPDX-FileCopyrightText: 2024 Shun Sakai
//
// SPDX-License-Identifier: Apache-2.0 OR MIT
package lzip_test
import (
"bufio"
"bytes"
"io"
"log"
"os"
"github.com/sorairolake/lzip-go"
)
func Example() {
const text = "The quick brown fox jumps over the lazy dog."
opt := &lzip.WriterOptions{4 * 1024 * 1024}
var buf bytes.Buffer
writer, err := lzip.NewWriterOptions(&buf, opt)
if err != nil {
log.Fatal(err)
}
if _, err := io.WriteString(writer, text); err != nil {
log.Fatal(err)
}
if err := writer.Close(); err != nil {
log.Fatal(err)
}
reader, err := lzip.NewReader(&buf)
if err != nil {
log.Fatal(err)
}
if _, err := io.Copy(os.Stdout, reader); err != nil {
log.Fatal(err)
}
// Output:
// The quick brown fox jumps over the lazy dog.
}
func ExampleReader() {
file, err := os.Open("testdata/fox.lz")
if err != nil {
log.Fatal(err)
}
defer file.Close()
reader, err := lzip.NewReader(bufio.NewReader(file))
if err != nil {
log.Print(err)
return
}
if _, err := io.Copy(os.Stdout, reader); err != nil {
log.Print(err)
return
}
// Output:
// The quick brown fox jumps over the lazy dog.
}
func ExampleWriter() {
const text = "The quick brown fox jumps over the lazy dog."
var buf bytes.Buffer
writer := lzip.NewWriter(&buf)
if _, err := io.WriteString(writer, text); err != nil {
log.Fatal(err)
}
if err := writer.Close(); err != nil {
log.Fatal(err)
}
// Output:
}