Add tar+gzip and tar+zstd compressed archive support.

This commit is contained in:
Catherine
2025-09-21 06:25:10 +00:00
parent 382bee9b4e
commit 2af2975713
5 changed files with 32 additions and 4 deletions

View File

@@ -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) {

View File

@@ -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)