Skip to content

Commit 3380ade

Browse files
committed
diff
1 parent 635729f commit 3380ade

File tree

9 files changed

+661
-34
lines changed

9 files changed

+661
-34
lines changed

bzip2.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package binarydist
2+
3+
import (
4+
"io"
5+
"os/exec"
6+
)
7+
8+
type bzip2Writer struct {
9+
c *exec.Cmd
10+
w io.WriteCloser
11+
}
12+
13+
func (w bzip2Writer) Write(b []byte) (int, error) {
14+
return w.w.Write(b)
15+
}
16+
17+
func (w bzip2Writer) Close() error {
18+
if err := w.w.Close(); err != nil {
19+
return err
20+
}
21+
return w.c.Wait()
22+
}
23+
24+
// Package compress/bzip2 implements only decompression,
25+
// so we'll fake it by running bzip2 in another process.
26+
func newBzip2Writer(w io.Writer) (wc io.WriteCloser, err error) {
27+
var bw bzip2Writer
28+
bw.c = exec.Command("bzip2", "-c")
29+
bw.c.Stdout = w
30+
31+
if bw.w, err = bw.c.StdinPipe(); err != nil {
32+
return nil, err
33+
}
34+
35+
if err = bw.c.Start(); err != nil {
36+
return nil, err
37+
}
38+
39+
return bw, nil
40+
}

common_test.go

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package binarydist
22

33
import (
44
"crypto/rand"
5+
"io"
56
"io/ioutil"
67
"os"
78
)
@@ -15,6 +16,14 @@ func mustOpen(path string) *os.File {
1516
return f
1617
}
1718

19+
func mustReadAll(r io.Reader) []byte {
20+
b, err := ioutil.ReadAll(r)
21+
if err != nil {
22+
panic(err)
23+
}
24+
return b
25+
}
26+
1827
func fileCmp(a, b *os.File) int64 {
1928
sa, err := a.Seek(0, 2)
2029
if err != nil {
@@ -58,7 +67,7 @@ func fileCmp(a, b *os.File) int64 {
5867
return -1
5968
}
6069

61-
func mustWriteRandFile(path string, size int) {
70+
func mustWriteRandFile(path string, size int) *os.File {
6271
p := make([]byte, size)
6372
_, err := rand.Read(p)
6473
if err != nil {
@@ -74,4 +83,11 @@ func mustWriteRandFile(path string, size int) {
7483
if err != nil {
7584
panic(err)
7685
}
86+
87+
_, err = f.Seek(0, 0)
88+
if err != nil {
89+
panic(err)
90+
}
91+
92+
return f
7793
}

0 commit comments

Comments
 (0)