2 ms·
> Every single PNG, including this one, starts with the same 8 bytes. This might be common on other platforms as well, but I know that Apple uses a kind of ser
by JKCalhoun 3y ago
> Every single PNG, including this one, starts with the same 8 bytes.
This might be common on other platforms as well, but I know that Apple uses a kind of series of tests to determine the type an image is rather than trusting the extension.
As an experiment, change a PNG to have a .JPEG extension on MacOS and double-click. Preview, unsurprisingly, launches — but if you get Info on the image in Preview it indicates it is a PNG. Of course.
- tiagod 3y agoUNIX systems, like Mac OS and Linux, use file[0] (or libmagic behind it), to determine the format of the file. (or shebang, if the file has one.) [0] https://en.m.wikipedia.org/wiki/File_(command) https://en.m.wikipedia.org/wiki/File_(command)
- wongarsu 3y agoFile extensions were the primary way to determine file type in VMS and CP/M. Consequently MS-DOS and Windows inherited that behavior. As you said, UNIX always went with heuristics based on the file content instead (and is the primary reason many file formats have fixed bytes to aid that process). And the web standarized on mime types transferred in the metadata, with how to set them correctly left as an exercise to the reader. Which usually means they are set based on file extension because that's faster.