github.com/andybalholm/brotli@v1.0.6/example_test.go (about)

     1  // Copyright 2016 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package brotli
     6  
     7  import (
     8  	"bytes"
     9  	"io"
    10  	"log"
    11  	"os"
    12  )
    13  
    14  func ExampleWriter_Reset() {
    15  	proverbs := []string{
    16  		"Don't communicate by sharing memory, share memory by communicating.\n",
    17  		"Concurrency is not parallelism.\n",
    18  		"The bigger the interface, the weaker the abstraction.\n",
    19  		"Documentation is for users.\n",
    20  	}
    21  
    22  	var b bytes.Buffer
    23  
    24  	bw := NewWriter(nil)
    25  	br := NewReader(nil)
    26  
    27  	for _, s := range proverbs {
    28  		b.Reset()
    29  
    30  		// Reset the compressor and encode from some input stream.
    31  		bw.Reset(&b)
    32  		if _, err := io.WriteString(bw, s); err != nil {
    33  			log.Fatal(err)
    34  		}
    35  		if err := bw.Close(); err != nil {
    36  			log.Fatal(err)
    37  		}
    38  
    39  		// Reset the decompressor and decode to some output stream.
    40  		if err := br.Reset(&b); err != nil {
    41  			log.Fatal(err)
    42  		}
    43  		if _, err := io.Copy(os.Stdout, br); err != nil {
    44  			log.Fatal(err)
    45  		}
    46  	}
    47  
    48  	// Output:
    49  	// Don't communicate by sharing memory, share memory by communicating.
    50  	// Concurrency is not parallelism.
    51  	// The bigger the interface, the weaker the abstraction.
    52  	// Documentation is for users.
    53  }