File: example_test.go

package info (click to toggle)
golang-github-andybalholm-brotli 1.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,432 kB
  • sloc: makefile: 2
file content (53 lines) | stat: -rw-r--r-- 1,213 bytes parent folder | download | duplicates (2)
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 2016 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package brotli

import (
	"bytes"
	"io"
	"log"
	"os"
)

func ExampleWriter_Reset() {
	proverbs := []string{
		"Don't communicate by sharing memory, share memory by communicating.\n",
		"Concurrency is not parallelism.\n",
		"The bigger the interface, the weaker the abstraction.\n",
		"Documentation is for users.\n",
	}

	var b bytes.Buffer

	bw := NewWriter(nil)
	br := NewReader(nil)

	for _, s := range proverbs {
		b.Reset()

		// Reset the compressor and encode from some input stream.
		bw.Reset(&b)
		if _, err := io.WriteString(bw, s); err != nil {
			log.Fatal(err)
		}
		if err := bw.Close(); err != nil {
			log.Fatal(err)
		}

		// Reset the decompressor and decode to some output stream.
		if err := br.Reset(&b); err != nil {
			log.Fatal(err)
		}
		if _, err := io.Copy(os.Stdout, br); err != nil {
			log.Fatal(err)
		}
	}

	// Output:
	// Don't communicate by sharing memory, share memory by communicating.
	// Concurrency is not parallelism.
	// The bigger the interface, the weaker the abstraction.
	// Documentation is for users.
}