make uncompress() public

This commit is contained in:
rhysd 2017-12-30 17:32:14 +09:00
parent 291b0ddedf
commit a12335af1a
3 changed files with 9 additions and 8 deletions

View File

@ -12,7 +12,8 @@ import (
"strings"
)
func uncompress(src io.Reader, url, cmd string) (io.Reader, error) {
// UncompressCommand uncompresses the given source. Archive and compression format is automatically detected from 'url' parameter, which represents the URL of asset. This returns a reader for the uncompressed command given by 'cmd'.
func UncompressCommand(src io.Reader, url, cmd string) (io.Reader, error) {
if strings.HasSuffix(url, ".zip") {
log.Println("Uncompressing zip file", url)

View File

@ -12,7 +12,7 @@ import (
func TestCompressionNotRequired(t *testing.T) {
buf := []byte{'a', 'b', 'c'}
want := bytes.NewReader(buf)
r, err := uncompress(want, "https://github.com/foo/bar/releases/download/v1.2.3/foo", "foo")
r, err := UncompressCommand(want, "https://github.com/foo/bar/releases/download/v1.2.3/foo", "foo")
if err != nil {
t.Fatal(err)
}
@ -49,7 +49,7 @@ func TestUncompress(t *testing.T) {
}
url := "https://github.com/foo/bar/releases/download/v1.2.3/bar" + ext
r, err := uncompress(f, url, "bar")
r, err := UncompressCommand(f, url, "bar")
if err != nil {
t.Fatal(err)
}
@ -89,7 +89,7 @@ func TestUncompressInvalidArchive(t *testing.T) {
}
url := "https://github.com/foo/bar/releases/download/v1.2.3/bar" + ext
_, err = uncompress(f, url, "bar")
_, err = UncompressCommand(f, url, "bar")
if err == nil {
t.Fatal("Error should be raised")
}
@ -110,7 +110,7 @@ func TestTargetNotFoundInZip(t *testing.T) {
t.Fatal(err)
}
_, err = uncompress(f, "https://github.com/foo/bar/releases/download/v1.2.3/bar.zip", "bar")
_, err = UncompressCommand(f, "https://github.com/foo/bar/releases/download/v1.2.3/bar.zip", "bar")
if err == nil {
t.Fatal("Error should be raised for")
}
@ -127,7 +127,7 @@ func TestTargetNotFoundInGZip(t *testing.T) {
t.Fatal(err)
}
_, err = uncompress(f, "https://github.com/foo/bar/releases/download/v1.2.3/bar.gzip", "bar")
_, err = UncompressCommand(f, "https://github.com/foo/bar/releases/download/v1.2.3/bar.gzip", "bar")
if err == nil {
t.Fatal("Error should be raised for")
}
@ -147,7 +147,7 @@ func TestTargetNotFoundInTarGz(t *testing.T) {
t.Fatal(err)
}
_, err = uncompress(f, "https://github.com/foo/bar/releases/download/v1.2.3/bar.tar.gz", "bar")
_, err = UncompressCommand(f, "https://github.com/foo/bar/releases/download/v1.2.3/bar.tar.gz", "bar")
if err == nil {
t.Fatal("Error should be raised for")
}

View File

@ -24,7 +24,7 @@ func UpdateTo(assetURL, cmdPath string) error {
defer res.Body.Close()
_, cmd := filepath.Split(cmdPath)
asset, err := uncompress(res.Body, assetURL, cmd)
asset, err := UncompressCommand(res.Body, assetURL, cmd)
if err != nil {
return err
}