mirror of
https://codeberg.org/git-pages/git-pages.git
synced 2026-05-20 22:21:33 +00:00
Add tar+gzip and tar+zstd compressed archive support.
This commit is contained in:
@@ -4,11 +4,13 @@ import (
|
||||
"archive/tar"
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"compress/gzip"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
|
||||
"github.com/klauspost/compress/zstd"
|
||||
"google.golang.org/protobuf/proto"
|
||||
)
|
||||
|
||||
@@ -69,6 +71,26 @@ func ExtractTar(reader io.Reader) (*Manifest, error) {
|
||||
return &manifest, nil
|
||||
}
|
||||
|
||||
func ExtractTarGzip(reader io.Reader) (*Manifest, error) {
|
||||
stream, err := gzip.NewReader(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
return ExtractTar(stream)
|
||||
}
|
||||
|
||||
func ExtractTarZstd(reader io.Reader) (*Manifest, error) {
|
||||
stream, err := zstd.NewReader(reader)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer stream.Close()
|
||||
|
||||
return ExtractTar(stream)
|
||||
}
|
||||
|
||||
var errZipBomb = errors.New("zip file size limit exceeded")
|
||||
|
||||
func ExtractZip(reader io.Reader) (*Manifest, error) {
|
||||
|
||||
@@ -114,7 +114,13 @@ func UpdateFromArchive(
|
||||
switch contentType {
|
||||
case "application/x-tar":
|
||||
log.Printf("update %s: (tar)", webRoot)
|
||||
manifest, err = ExtractTar(reader) // yellow? definitely yellow.
|
||||
manifest, err = ExtractTar(reader) // yellow?
|
||||
case "application/x-tar+gzip":
|
||||
log.Printf("update %s: (tar.gz)", webRoot)
|
||||
manifest, err = ExtractTarGzip(reader) // definitely yellow.
|
||||
case "application/x-tar+zstd":
|
||||
log.Printf("update %s: (tar.zst)", webRoot)
|
||||
manifest, err = ExtractTarZstd(reader)
|
||||
case "application/zip":
|
||||
log.Printf("update %s: (zip)", webRoot)
|
||||
manifest, err = ExtractZip(reader)
|
||||
|
||||
Reference in New Issue
Block a user