Skip to content

Instantly share code, notes, and snippets.

@wjessop
Created July 4, 2013 21:25
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save wjessop/5930326 to your computer and use it in GitHub Desktop.
package backup_downloader
import (
"bytes"
"io"
"log"
"os"
"os/exec"
"sync"
)
func decompressLzopPipe(decompressed_out io.Writer) (*io.PipeWriter, *sync.WaitGroup) {
reader, writer := io.Pipe()
cmd := exec.Command("lzop", "-d")
var wg sync.WaitGroup
wg.Add(1)
go func() {
var out bytes.Buffer // We save the stdout and print it if there is an error
cmd.Stdin = reader
cmd.Stdout = decompressed_out
cmd.Stderr = &out
err := cmd.Run()
if err != nil {
io.Copy(os.Stdout, io.Reader(&out))
log.Fatal(err)
}
wg.Done()
}()
return writer, &wg
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment