File: bzip2.go

package info (click to toggle)
golang-github-kr-binarydist 0.1.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 140 kB
  • sloc: makefile: 13
file content (40 lines) | stat: -rw-r--r-- 697 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
package binarydist

import (
	"io"
	"os/exec"
)

type bzip2Writer struct {
	c *exec.Cmd
	w io.WriteCloser
}

func (w bzip2Writer) Write(b []byte) (int, error) {
	return w.w.Write(b)
}

func (w bzip2Writer) Close() error {
	if err := w.w.Close(); err != nil {
		return err
	}
	return w.c.Wait()
}

// Package compress/bzip2 implements only decompression,
// so we'll fake it by running bzip2 in another process.
func newBzip2Writer(w io.Writer) (wc io.WriteCloser, err error) {
	var bw bzip2Writer
	bw.c = exec.Command("bzip2", "-c")
	bw.c.Stdout = w

	if bw.w, err = bw.c.StdinPipe(); err != nil {
		return nil, err
	}

	if err = bw.c.Start(); err != nil {
		return nil, err
	}

	return bw, nil
}