1// Copyright 2014-2017 Ulrich Kunitz. 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// +build ignore 6 7package main 8 9import ( 10 "bytes" 11 "io" 12 "log" 13 "os" 14 15 "github.com/ulikunitz/xz" 16) 17 18func main() { 19 const text = "The quick brown fox jumps over the lazy dog.\n" 20 var buf bytes.Buffer 21 // compress text 22 w, err := xz.NewWriter(&buf) 23 if err != nil { 24 log.Fatalf("xz.NewWriter error %s", err) 25 } 26 if _, err := io.WriteString(w, text); err != nil { 27 log.Fatalf("WriteString error %s", err) 28 } 29 if err := w.Close(); err != nil { 30 log.Fatalf("w.Close error %s", err) 31 } 32 // decompress buffer and write output to stdout 33 r, err := xz.NewReader(&buf) 34 if err != nil { 35 log.Fatalf("NewReader error %s", err) 36 } 37 if _, err = io.Copy(os.Stdout, r); err != nil { 38 log.Fatalf("io.Copy error %s", err) 39 } 40} 41