Parcourir la source

pkg/archive: DetectCompression(): use bytes.HasPrefix()

The existing code was the exact equivalent of bytes.HasPrefix();

    // HasPrefix tests whether the byte slice s begins with prefix.
    func HasPrefix(s, prefix []byte) bool {
    	return len(s) >= len(prefix) && Equal(s[0:len(prefix)], prefix)
    }

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Sebastiaan van Stijn il y a 3 ans
Parent
commit
b321474747
1 fichiers modifiés avec 1 ajouts et 4 suppressions
  1. 1 4
      pkg/archive/archive.go

+ 1 - 4
pkg/archive/archive.go

@@ -129,10 +129,7 @@ func DetectCompression(source []byte) Compression {
 		Gzip:  {0x1F, 0x8B, 0x08},
 		Gzip:  {0x1F, 0x8B, 0x08},
 		Xz:    {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
 		Xz:    {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
 	} {
 	} {
-		if len(source) < len(m) {
-			continue
-		}
-		if bytes.Equal(m, source[:len(m)]) {
+		if bytes.HasPrefix(source, m) {
 			return compression
 			return compression
 		}
 		}
 	}
 	}