File Extensions, Signatures, and Structure
An extension records a naming convention. A signature and a parser inspect evidence contained within the file.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 4
- Reading time
- 1 min
In this article4 chapters
Compare names and contents
A file called report.csv could contain encoded JSON or plain text. Renaming it changes the hint without converting the data. A suffix test can filter candidate names before inspecting the actual content.
Validate where the data is read
A recognized header can indicate the intended format while a later record is incomplete. Use a parser with the expected structure and report where it fails. Length-prefixed records illustrate one kind of internal check.[1]
Use a complete parser after a header check
A file named report.json might contain ordinary prose or a truncated object. An opening brace suggests an object but does not prove well-formed JSON. Validate complete syntax and then verify the expected application fields. See structural versus domain validation.
report.json with text "hello" without quotes → parse failure
Beginning with { and ending prematurely → parse failure
{} → valid JSON object, still compare its contents to the schema
Keep the filename useful without making it authoritative
Extensions aid display, selection and routing. File signatures can help identify binary formats and can also be insufficient on their own. Test a valid input with a misleading name and a malformed file with the expected extension.