Mac OS X Finder 如何识别 PNG 文件?
我在 Finder 中有一个最初名为“foo”的文件。如果我“获取文件信息”,Finder 会将其识别为“种类:纯文本”。如果我将文件重命名为“foo.png”,Finder 会将其识别为“种类:便携式网络图形图像”。如果我将文件重命名为“foo”,Finder 仍会将其识别为“种类:便携式网络图形图像”(不像我预期的那样是纯文本)。
Mac OS X 如何识别文件类型?
I have a file which was originally named 'foo' in the Finder. If I 'get info' for the file, the Finder recognizes it as "Kind: Plain text". If I rename the file as 'foo.png', Finder then recognizes it as "Kind: Portable Network Graphics image". If I rename the file as 'foo', Finder still recognizes it as "Kind: Portable Networks Graphics image" (not plain text like I expected).
How is Mac OS X recognizing the file kind?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
文件中的幻数通常就是这样工作的。例如,PNG 文件有一个标头,用于将其标识为 PNG 而不是其他文件格式。 维基百科有更多信息。
Magic numbers in the file is usually how it works. A PNG file, for example, has a header to identify it as PNG and not some other file format. Wikipedia has some more info.
我不知道它是如何工作的,但我可以想象,直到您将文件重命名为
foo.png
Finder 并不知道也不关心它是什么类型。但是,在您将其重命名后,Finder 将其类型与 inode ID 一起存储在某处(也许是.DS_Store
?),这样即使您再次重命名它,它也可以识别该文件。I don't know how it works, but I can imagine that until you renamed the file to
foo.png
Finder didn't know and didn't care what type it is. But after you've renamed it Finder stored it's type somewhere (.DS_Store
perhaps?) with the inode ID so it could recognize this file even after you rename it again.因为 *NIX 系统(如 Mac OS X)不依赖扩展名来识别文件类型。他们依赖于一种叫做“Magic Number”的东西(如果我没记错的话),也就是说,他们搜索在这些类型的文件中找到的常见模式(例如标题、标签、元信息等)并识别它们。
Because *NIX systems (like Mac OS X) don't rely on extensions to recognize file types. They rely on something called Magic Number (if I remember well), that is, they search for common patterns found in those types of file (e.g headers, tags, metainfo etc.) and they recognize them.