diff --git a/archive/archive.go b/archive/archive.go index 5d29ce8193..160ea0737e 100644 --- a/archive/archive.go +++ b/archive/archive.go @@ -2,6 +2,7 @@ package archive import ( "bufio" + "bytes" "compress/bzip2" "compress/gzip" "errors" @@ -42,26 +43,16 @@ const ( ) func DetectCompression(source []byte) Compression { - sourceLen := len(source) for compression, m := range map[Compression][]byte{ Bzip2: {0x42, 0x5A, 0x68}, Gzip: {0x1F, 0x8B, 0x08}, Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00}, } { - fail := false - if len(m) > sourceLen { + if len(source) < len(m) { utils.Debugf("Len too short") continue } - i := 0 - for _, b := range m { - if b != source[i] { - fail = true - break - } - i++ - } - if !fail { + if bytes.Compare(m, source[:len(m)]) == 0 { return compression } }