Expand description
§Palate
File type detection combining the best of tft and hyperpolyglot.
§Acknowledgments
This project is a reassembly of code from several excellent projects:
- tft - Tree-sitter File Type, providing fast file type detection using tree-sitter grammars
- Neovim - The original source of filetype detection heuristics and patterns
- hyperpolyglot - Language detection library with comprehensive language patterns
This crate essentially combines and curates the detection logic from these sources into a unified, ergonomic API.
§License
GPL-3.0-or-later
This project is derived from tft (GPL-3.0-or-later), which itself incorporates code from Neovim (Apache-2.0/Vim license). As a derivative of GPL-3.0 work, this project is licensed under GPL-3.0-or-later.
§Features
- Comprehensive file type detection
- Fast PHF-based lookups
- Content-based detection with heuristics
- Shebang interpretation support
- Naive Bayes classifier fallback (with
classifierfeature)
§Usage
use palate::{detect, FileType};
// Detect file type with fallback to Text
let ft = detect("main.rs", "");
assert_eq!(FileType::Rust, ft);
// Try detection without fallback
let ft = palate::try_detect("unknown.xyz", "");
assert_eq!(None, ft);§Detection Pipeline
- Path suffix matching
- Filename matching
- Pattern matching (with priorities)
- File extension matching (PHF map)
- Negative priority patterns
- Content-based detection (dynamic resolvers)
§Features
detect(default): Enable file type detectionclassifier: Enable naive Bayes classifierserde: Enable serde serialization for FileType
Structs§
- Peekable
Reader - A reader that can peek at content without consuming the stream.
Enums§
- File
Type - A non-exhaustive list of text file types.
Functions§
- detect
- Same as
try_detectbut automatically falling back toFileType::Textwheretry_detectwould returnNone. - detect_
with_ reader - Detect file type from path and peekable reader using the detection pipeline.
- is_
text_ file - Check if a file is text (not binary).
- try_
detect - Try to detect a
FileTypegiven a file’s path and content.