mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
archive: simplify DetectCompression
Docker-DCO-1.1-Signed-off-by: Johan Euphrosine <proppy@google.com> (github: proppy)
This commit is contained in:
parent
58b49e60bb
commit
3118952e0a
1 changed files with 1 additions and 15 deletions
|
@ -42,26 +42,12 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
func DetectCompression(source []byte) Compression {
|
func DetectCompression(source []byte) Compression {
|
||||||
sourceLen := len(source)
|
|
||||||
for compression, m := range map[Compression][]byte{
|
for compression, m := range map[Compression][]byte{
|
||||||
Bzip2: {0x42, 0x5A, 0x68},
|
Bzip2: {0x42, 0x5A, 0x68},
|
||||||
Gzip: {0x1F, 0x8B, 0x08},
|
Gzip: {0x1F, 0x8B, 0x08},
|
||||||
Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
|
Xz: {0xFD, 0x37, 0x7A, 0x58, 0x5A, 0x00},
|
||||||
} {
|
} {
|
||||||
fail := false
|
if bytes.Compare(m, source[:len(m)]) == 0 {
|
||||||
if len(m) > sourceLen {
|
|
||||||
utils.Debugf("Len too short")
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
i := 0
|
|
||||||
for _, b := range m {
|
|
||||||
if b != source[i] {
|
|
||||||
fail = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
i++
|
|
||||||
}
|
|
||||||
if !fail {
|
|
||||||
return compression
|
return compression
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue