mirror of
https://github.com/apricote/hcloud-upload-image.git
synced 2026-01-13 21:31:03 +00:00
feat: Add zstd support
This commit is contained in:
parent
75bca91334
commit
bca575224f
4 changed files with 22 additions and 4 deletions
|
|
@ -104,9 +104,10 @@ const (
|
|||
CompressionNone Compression = ""
|
||||
CompressionBZ2 Compression = "bz2"
|
||||
CompressionXZ Compression = "xz"
|
||||
CompressionZSTD Compression = "zstd"
|
||||
|
||||
// Possible future additions:
|
||||
// zip,zstd
|
||||
// zip
|
||||
)
|
||||
|
||||
type Format string
|
||||
|
|
@ -524,6 +525,8 @@ func assembleCommand(options UploadOptions) (string, error) {
|
|||
cmd += "bzip2 -cd | "
|
||||
case CompressionXZ:
|
||||
cmd += "xz -cd | "
|
||||
case CompressionZSTD:
|
||||
cmd += "zstd -cd | "
|
||||
default:
|
||||
return "", fmt.Errorf("unknown compression: %q", options.ImageCompression)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -48,6 +48,21 @@ func TestAssembleCommand(t *testing.T) {
|
|||
},
|
||||
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.xz\" | xz -cd | dd of=/dev/sda bs=4M && sync'",
|
||||
},
|
||||
{
|
||||
name: "local zstd",
|
||||
options: UploadOptions{
|
||||
ImageCompression: CompressionZSTD,
|
||||
},
|
||||
want: "bash -c 'set -euo pipefail && zstd -cd | dd of=/dev/sda bs=4M && sync'",
|
||||
},
|
||||
{
|
||||
name: "remote zstd",
|
||||
options: UploadOptions{
|
||||
ImageURL: mustParseURL("https://example.com/image.zst"),
|
||||
ImageCompression: CompressionZSTD,
|
||||
},
|
||||
want: "bash -c 'set -euo pipefail && wget --no-verbose -O - \"https://example.com/image.zst\" | zstd -cd | dd of=/dev/sda bs=4M && sync'",
|
||||
},
|
||||
{
|
||||
name: "local bz2",
|
||||
options: UploadOptions{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue