Supported File Formats
uViewFile relies on file signatures (magic numbers) rather than extensions to determine file type.
OS environments inherently trust the file extension provided by the user or the downloader. This is a primary vector for malware distribution. We ignore the extension and analyze the raw bytes.
Document Formats
| Format | Extension | Magic Number (Hex) |
|---|---|---|
| PDF Document | 25 50 44 46 2D | |
| Office Open XML | .docx, .xlsx | 50 4B 03 04 |
| Legacy Office | .doc, .xls | D0 CF 11 E0 A1 B1 1A E1 |
| Rich Text Format | .rtf | 7B 5C 72 74 66 31 |
Executable Formats
| Format | Extension | Magic Number (Hex) |
|---|---|---|
| Windows PE Executable | .exe, .dll | 4D 5A |
| Linux ELF Executable | .elf, .so | 7F 45 4C 46 |
| Mach-O Binary | .macho, .dylib | FE ED FA CE / FE ED FA CF |
| Java Class | .class | CA FE BA BE |
Image & Media Formats
| Format | Extension | Magic Number (Hex) |
|---|---|---|
| JPEG Image | .jpg, .jpeg | FF D8 FF E0 |
| PNG Image | .png | 89 50 4E 47 0D 0A 1A 0A |
| GIF Image | .gif | 47 49 46 38 37 61 / 47 49 46 38 39 61 |
| WebP Image | .webp | 52 49 46 46 ... 57 45 42 50 |
Wait, docx is a ZIP?
Yes. Modern Office formats (.docx, .xlsx, .pptx) are actually ZIP archives containing XML files. That's why their magic number (50 4B 03 04) matches standard ZIP files. uViewFile will parse the internal structure to differentiate them.
FAQ
Why does my file show as "application/octet-stream"?
If a file lacks a recognizable magic number, it is treated as raw binary data. This often happens with proprietary game files, encrypted containers, or flat configuration files.
Can a magic number be spoofed?
Yes. Malware authors sometimes prepend fake headers (like a JPEG magic number) to a malicious payload to confuse rudimentary security scanners. This is why deep analysis (entropy, structure validation) is required alongside signature matching.
Internal References
Common Mistakes
| Mistake | Consequence | Better Approach |
|---|---|---|
| FileReader.readAsArrayBuffer | Browser Crash (OOM) | Use File.slice for chunks |
| Rendering full DOM | Browser freeze | Virtualized list rendering |
FAQ
What is the max file size?
By using slicing and streams, we can handle files limited only by your OS filesystem (e.g., 2TB on NTFS), not your RAM.