Skip to content

Commit

Permalink
Merge pull request #75 from k1LoW/support-tar.bz2
Browse files Browse the repository at this point in the history
Support bzip2
  • Loading branch information
k1LoW authored Apr 21, 2023
2 parents 062fc98 + 5903f47 commit 23dcb7e
Showing 1 changed file with 31 additions and 8 deletions.
39 changes: 31 additions & 8 deletions gh/gh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package gh
import (
"archive/zip"
"bytes"
"compress/bzip2"
"compress/gzip"
"context"
"errors"
Expand Down Expand Up @@ -40,6 +41,9 @@ var supportContentType = []string{
"application/x-zip-compressed",
// tar.gz
"application/gzip",
"application/x-gzip",
// tar.bz2
"application/x-bzip2",
// binary
"application/octet-stream",
}
Expand Down Expand Up @@ -210,19 +214,38 @@ func makeFS(ctx context.Context, b []byte, repo, name string, contentTypes []str
return nil, err
}
return fsys, nil
} else {
b, err := io.ReadAll(gr)
}
b, err := io.ReadAll(gr)
if err != nil {
return nil, err
}
fsys := fstest.MapFS{}
fsys[repo] = &fstest.MapFile{
Data: b,
Mode: fs.ModePerm,
ModTime: time.Now(),
}
return fsys, nil
case matchContentTypes([]string{"application/x-bzip2"}, contentTypes):
br := bzip2.NewReader(bytes.NewReader(b))
if strings.HasSuffix(name, ".tar.bz2") {
fsys, err := tarfs.New(br)
if err != nil {
return nil, err
}
fsys := fstest.MapFS{}
fsys[repo] = &fstest.MapFile{
Data: b,
Mode: fs.ModePerm,
ModTime: time.Now(),
}
return fsys, nil
}
b, err := io.ReadAll(br)
if err != nil {
return nil, err
}
fsys := fstest.MapFS{}
fsys[repo] = &fstest.MapFile{
Data: b,
Mode: fs.ModePerm,
ModTime: time.Now(),
}
return fsys, nil
case matchContentTypes([]string{"application/octet-stream"}, contentTypes):
fsys := fstest.MapFS{}
fsys[repo] = &fstest.MapFile{
Expand Down

0 comments on commit 23dcb7e

Please sign in to comment.