diff --git a/Cargo.lock b/Cargo.lock index 37fce76..6aa84ce 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "auto_encoder" -version = "0.1.3" +version = "0.1.4" dependencies = [ "chardetng", "encoding_rs", diff --git a/Cargo.toml b/Cargo.toml index 80757ac..d9f4791 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "auto_encoder" -version = "0.1.3" +version = "0.1.4" edition = "2021" description = "Auto encoding library" repository = "https://github.com/spider-rs/auto-encoder" diff --git a/src/lib.rs b/src/lib.rs index 892517d..db0151b 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -204,6 +204,10 @@ pub fn encoding_for_locale(locale: &str) -> Option<&'static encoding_rs::Encodin /// Checks if the file is a known binary format using its initial bytes. pub fn is_binary_file(content: &[u8]) -> bool { + if content.is_empty() { + return false; + } + if let Some(&keys) = FIRST_BYTE_MAP.get(&content[0]) { for &key in keys { if let Some(&k) = ASSET_NUMBERS.get(key) {