Some checks failed
Build / build (mipsle) (push) Waiting to run
Build / build (ppc64) (push) Waiting to run
Build / build (ppc64le) (push) Waiting to run
Build / build (riscv64) (push) Waiting to run
Build / build (s390x) (push) Waiting to run
Build / build (amd64) (push) Has been cancelled
Build / build (386) (push) Has been cancelled
Build / build (mips64le) (push) Has been cancelled
Build / build (arm) (push) Has been cancelled
Build / build (mips64) (push) Has been cancelled
Build / build (mips) (push) Has been cancelled
Build / build (loong64) (push) Has been cancelled
Build / build (arm64) (push) Has been cancelled
Signed-off-by: Matheus Sampaio Queiroga <srherobrine20@gmail.com>
37 lines
704 B
Go
37 lines
704 B
Go
package dpkg
|
|
|
|
import (
|
|
"bytes"
|
|
"io"
|
|
)
|
|
|
|
func compressExt(r io.Reader) (string, io.Reader, error) {
|
|
// Read fist bytes to detect file compression
|
|
buf := make([]byte, 15)
|
|
if _, err := r.Read(buf); err != nil {
|
|
return "", r, err
|
|
}
|
|
|
|
// Concat read bytes
|
|
r = io.MultiReader(bytes.NewReader(buf), r)
|
|
|
|
switch {
|
|
// Gzip
|
|
case bytes.HasPrefix(buf, []byte{0x1F, 0x8B, 0x08}):
|
|
return ".gz", r, nil
|
|
|
|
// BZip2
|
|
case bytes.HasPrefix(buf, []byte{0x5A, 0x42}):
|
|
return ".bz2", r, nil
|
|
|
|
// XZ
|
|
case bytes.HasPrefix(buf, []byte{0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}):
|
|
return ".xz", r, nil
|
|
|
|
// Zstd
|
|
case bytes.HasPrefix(buf, []byte{0xB5, 0x28, 0xFD, 0x2F}):
|
|
return ".zst", r, nil
|
|
}
|
|
return "", r, nil
|
|
}
|