Skip to content

Commit

Permalink
chore(detection): add pdf files to asset detection
Browse files Browse the repository at this point in the history
  • Loading branch information
j-mendez committed Oct 22, 2024
1 parent 91320e0 commit fe10935
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 10 deletions.
14 changes: 7 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "auto_encoder"
version = "0.1.4"
version = "0.1.5"
edition = "2021"
description = "Auto encoding library"
repository = "https://github.com/spider-rs/auto-encoder"
Expand Down
15 changes: 13 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ use phf::phf_map;
/// Define a map of file types to their numbers
pub static ASSET_NUMBERS: phf::Map<&'static str, &'static [u8]> = phf_map! {
"jpeg" => &[0xFF, 0xD8, 0xFF],
"pdf" => b"%PDF",
"png" => &[0x89, 0x50, 0x4E, 0x47],
"gif" => &[0x47, 0x49, 0x46, 0x38],
"bmp" => &[0x42, 0x4D],
Expand All @@ -79,24 +80,34 @@ pub static ASSET_NUMBERS: phf::Map<&'static str, &'static [u8]> = phf_map! {
"zip" => &[0x50, 0x4B, 0x03, 0x04],
"gzip" => &[0x1F, 0x8B],
"bzip" => &[0x42, 0x5A, 0x68],
"bzip2" => &[0x42, 0x5A, 0x68], // BZip2, "BZh"
"java_class" => &[0xCA, 0xFE, 0xBA, 0xBE],
"lha" => &[0x4C], // Placeholder or check specific variant
"elf" => &[0x7F, 0x45, 0x4C, 0x46], // 0x7F followed by 'ELF'
};

/// Map of first byte to the corresponding magic number key(s)
pub static FIRST_BYTE_MAP: phf::Map<u8, &'static [&'static str]> = phf_map! {
0xFFu8 => &["jpeg", "mp3_no_id3"],
0x89u8 => &["png"],
0x47u8 => &["gif"],
0x42u8 => &["bmp", "bzip"],
0x42u8 => &["bmp", "bzip", "bzip2"],
0x49u8 => &["tiff_le", "mp3_id3"],
0x4Du8 => &["tiff_be"],
0x4Fu8 => &["ogg"],
0x66u8 => &["flac"],
0x52u8 => &["riff"],
0x52u8 => &["riff", "rar"],
0x00u8 => &["mpg_mpeg", "mp4", "mpeg_1b3"],
0x1Au8 => &["mkv"],
0x46u8 => &["flv"],
0x50u8 => &["zip"],
0x1Fu8 => &["gzip"],
0x25u8 => &["pdf"],
0x38u8 => &["gif"],
0x5Au8 => &["7z"],
0xCAu8 => &["java_class"],
0x4Cu8 => &["lha"],
0x7Fu8 => &["elf"],
};

/// Encoding to detect for locales
Expand Down

0 comments on commit fe10935

Please sign in to comment.