MCPcopy Create free account
hub / github.com/aptly-dev/aptly / CompressFile

Function CompressFile

utils/compress.go:15–38  ·  view source on GitHub ↗

CompressFile compresses file specified by source to .gz & .bz2 It uses internal gzip and external bzip2, see: https://code.google.com/p/go/issues/detail?id=4828

(source *os.File, onlyGzip bool)

Source from the content-addressed store, hash-verified

13// It uses internal gzip and external bzip2, see:
14// https://code.google.com/p/go/issues/detail?id=4828
15func CompressFile(source *os.File, onlyGzip bool) error {
16 gzPath := source.Name() + ".gz"
17 gzFile, err := os.Create(gzPath)
18 if err != nil {
19 return err
20 }
21 defer func() {
22 _ = gzFile.Close()
23 }()
24
25 gzWriter := pgzip.NewWriter(gzFile)
26 defer func() {
27 _ = gzWriter.Close()
28 }()
29
30 _, _ = source.Seek(0, 0)
31 _, err = io.Copy(gzWriter, source)
32 if err != nil || onlyGzip {
33 return err
34 }
35
36 cmd := exec.Command("bzip2", "-k", "-f", source.Name())
37 return cmd.Run()
38}

Callers 2

FinalizeMethod · 0.92
TestCompressMethod · 0.85

Calls 3

RunMethod · 0.80
CloseMethod · 0.65
CopyMethod · 0.45

Tested by 1

TestCompressMethod · 0.68