{"id":20549,"date":"2018-02-15T16:32:06","date_gmt":"2018-02-15T21:32:06","guid":{"rendered":"https:\/\/mjtsai.com\/blog\/?p=20549"},"modified":"2019-12-19T14:58:01","modified_gmt":"2019-12-19T19:58:01","slug":"can-macos-tell-how-large-a-file-really-is","status":"publish","type":"post","link":"https:\/\/mjtsai.com\/blog\/2018\/02\/15\/can-macos-tell-how-large-a-file-really-is\/","title":{"rendered":"Can macOS Tell How Large a File Really Is?"},"content":{"rendered":"<p><a href=\"https:\/\/eclecticlight.co\/2018\/02\/12\/can-macos-tell-how-large-a-file-really-is\/\">Howard Oakley<\/a>:<\/p>\n<blockquote cite=\"https:\/\/eclecticlight.co\/2018\/02\/12\/can-macos-tell-how-large-a-file-really-is\/\">\n<p>The macOS programming class which provides most information about files is <code>URL<\/code>. It has quite an elaborate interface which involves telling a file URL object which &lsquo;keys&rsquo; you want it to reveal, then accessing those that you want. In this case, the URLResourceKey in question is <code>totalFileSize<\/code>, which Apple&rsquo;s developer documentation describes as:<\/p>\n<blockquote><p>Key for the total displayable size of the file in bytes, returned as an NSNumber object (read-only). This includes the size of any file metadata.<\/p><\/blockquote>\n<\/blockquote>\n<p>But apparently this refers to metadata from the resource fork. It does not count extended attributes.<\/p>\n<blockquote cite=\"https:\/\/eclecticlight.co\/2018\/02\/12\/can-macos-tell-how-large-a-file-really-is\/\">\n<p>The evidence from Precize is that the only accurate way to measure the full size of a Mac file is to total the sizes of each of its xattrs, and add those to the size of its data fork. That doesn&rsquo;t appear to be a function performed by macOS, or at least it is not exposed anywhere to developers or users. So, as far as I can tell, macOS itself doesn&rsquo;t have any direct access to the total size of any of its files &#x2013; which seems a startling omission.<\/p>\n<\/blockquote>\n\n<p><a href=\"https:\/\/eclecticlight.co\/2018\/02\/14\/where-are-all-those-extended-attributes\/\">Howard Oakley<\/a>:<\/p>\n<blockquote cite=\"https:\/\/eclecticlight.co\/2018\/02\/14\/where-are-all-those-extended-attributes\/\">\n<p>I had not expected xattrs to be so heavily used in the \/Library folder, but the average size of xattrs across its files which have xattrs is just over 7 KB per file. I had expected them to be commonplace in my Home folder, but am surprised that the average total size of xattrs across all the files there (not just with xattrs) is just over 2 KB.<\/p>\n<p>[&#8230;]<\/p>\n<p>The largest contribution is in <tt>~\/Documents<\/tt>, which has a total of 2.6 GB of xattrs across less than half a million files. However, a lot of my images in <tt>~\/Pictures<\/tt> still seem to sport thumbnails, so the average total of xattrs per file with xattrs is there almost 21 KB &#x2013; that&rsquo;s 0.796 GB in only 38018 files.<\/p>\n<\/blockquote>","protected":false},"excerpt":{"rendered":"<p>Howard Oakley: The macOS programming class which provides most information about files is URL. It has quite an elaborate interface which involves telling a file URL object which &lsquo;keys&rsquo; you want it to reveal, then accessing those that you want. In this case, the URLResourceKey in question is totalFileSize, which Apple&rsquo;s developer documentation describes as: [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"apple_news_api_created_at":"2019-12-19T19:58:04Z","apple_news_api_id":"72c823d0-3fa6-43eb-b3bf-40f46f37f429","apple_news_api_modified_at":"2019-12-19T19:58:05Z","apple_news_api_revision":"AAAAAAAAAAD\/\/\/\/\/\/\/\/\/\/w==","apple_news_api_share_url":"https:\/\/apple.news\/Acsgj0D-mQ-uzv0D0bzf0KQ","apple_news_coverimage":0,"apple_news_coverimage_caption":"","apple_news_is_hidden":false,"apple_news_is_paid":false,"apple_news_is_preview":false,"apple_news_is_sponsored":false,"apple_news_maturity_rating":"","apple_news_metadata":"\"\"","apple_news_pullquote":"","apple_news_pullquote_position":"","apple_news_slug":"","apple_news_sections":"\"\"","apple_news_suppress_video_url":false,"apple_news_use_image_component":false,"footnotes":""},"categories":[],"tags":[131,69,1902,30,1529,608],"class_list":["post-20549","post","type-post","status-publish","format-standard","hentry","tag-bug","tag-cocoa","tag-extended-attributes","tag-mac","tag-macos-10-13","tag-metadata"],"apple_news_notices":[],"_links":{"self":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/20549","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/comments?post=20549"}],"version-history":[{"count":1,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/20549\/revisions"}],"predecessor-version":[{"id":20550,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/posts\/20549\/revisions\/20550"}],"wp:attachment":[{"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/media?parent=20549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/categories?post=20549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/mjtsai.com\/blog\/wp-json\/wp\/v2\/tags?post=20549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}