pub struct Pending { /* private fields */ }Expand description
A classification waiting for file content (see classify()).
Content is needed when the name gives no text/binary tag (unknown
names and EXTENSIONS_NEED_BINARY_CHECK
entries) and, for executable files with an unknown name, to read the
shebang.
Implementations§
Source§impl Pending
impl Pending
The tags known so far (type, mode and name tags).
Sourcepub const fn needs_shebang(&self) -> bool
pub const fn needs_shebang(&self) -> bool
Whether the shebang must be parsed (an executable file whose name gave no tags).
Sourcepub const fn needs_encoding(&self) -> bool
pub const fn needs_encoding(&self) -> bool
Whether text/binary must be decided from the content (always
true when needs_shebang is).
Sourcepub fn finish<R: Read>(self, reader: R) -> Result<TagSet>
pub fn finish<R: Read>(self, reader: R) -> Result<TagSet>
Finish from the file’s content read from its start.
Reads TEXT_PROBE_LEN bytes (fewer at end of input); only a shebang
line longer than that reads further, bounded by
MAX_SHEBANG_BYTES.
§Errors
Propagates read errors.
Sourcepub fn finish_bytes(self, content: &[u8]) -> TagSet
pub fn finish_bytes(self, content: &[u8]) -> TagSet
Finish from in-memory content (the whole file or at least its first
TEXT_PROBE_LEN bytes plus the shebang line).
use file_identify::{Classification, Meta, classify};
let Classification::NeedsContent(pending) = classify(Meta::regular(true), "bin/tool") else {
unreachable!()
};
let tags = pending.finish_bytes(b"#!/usr/bin/env python3\nprint('hi')\n");
assert_eq!(tags.to_string(), "executable, file, python, python3, text");