Skip to content

Commit

Permalink
pkg/archive: DetectCompression(): use bytes.HasPrefix()
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
thaJeztah authored and Romain-Geissler-1A committed Mar 5, 2022
1 parent c3dec60 commit ca3c8e0
Showing 1 changed file with 1 addition and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/archive/archive.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,7 @@ func DetectCompression(source []byte) Compression {
Gzip: {0x1F, 0x8B, 0x08},
Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
} {
if len(source) < len(m) {
logrus.Debug("Len too short")
continue
}
if bytes.Equal(m, source[:len(m)]) {
if bytes.HasPrefix(source, m) {
return compression
}
}
Expand Down

0 comments on commit ca3c8e0

Please sign in to comment.