recognize static method
Returns the format the data starts with, or ArchiveFormat.unknown.
zlib is checked last: its 2-byte header has no magic and can match the
start of other formats. withZLib is off by default for the same reason,
since the check gives false positives.
Implementation
static ArchiveFormat recognize(List<int> data, {bool withZLib = false}) {
if (isTar(data)) {
return ArchiveFormat.tar;
}
if (isXZ(data)) {
return ArchiveFormat.xz;
}
if (isZstd(data)) {
return ArchiveFormat.zstd;
}
if (isZip(data)) {
return ArchiveFormat.zip;
}
// Last ones in order to ensure valid most-common archives are not
// recognized for text files that start with magic from these codecs
if (isGZip(data)) {
return ArchiveFormat.gzip;
}
if (isBZip2(data)) {
return ArchiveFormat.bzip2;
}
if (withZLib && isZLib(data)) {
return ArchiveFormat.zlib;
}
return ArchiveFormat.unknown;
}