-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
It is based on the one for flate.Writer.Reset. Fixes #31.
- Loading branch information
1 parent
1d75021
commit 34a5640
Showing
1 changed file
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. | ||
} |