macOS Finder still can't work out the size of files
For the last six years I have been concerned that file sizes shown by the Finder aren’t accurate. Go back to the last century, and that was something that Classic Mac OS got right. To get the definitive answer, all you had to do was use ResEdit’s Get Info command.
In those days, files came with two forks, regular data and the Resource Fork. This dialog gives the size in bytes for each, in this case 117,836 in the Resource fork, and 144,788 bytes data.
In January 2018, High Sierra couldn’t match that.
The size of this text file is given as 391 bytes in the Finder’s Get Info, but as you’ll see below it contains over 90,000 bytes of extended attributes that figure simply ignores.
Since then, macOS has tried harder, but still isn’t up to the job, as shown in Sonoma 14.4.1.
Here Get Info claims this crafted example file is 263,195 bytes in size.
My free utility Precize begs to differ: according to figures obtained from the file system, there are 183,136 bytes of data and 161,326 bytes of extended attributes, coming to a total of 344,462 bytes.
That’s not surprising, as xattred reveals that it has two extended attributes each of 80,059 bytes accounting for much of their size.
The clue as to what the Finder is getting wrong comes in the URL Keys line from Precize, where the total size matches that given by the Finder, 263,195 bytes. So how come information taken from the URL of a file can get its size so wrong?
As Precize shows, those figures are derived from two different sources. The correct numbers come from the size
key in its file attribute dictionary “whose value indicates the file’s size in bytes.” To that, Apple adds a highlighted box marked Important, and explains that “if the file has a resource fork, the returned value does not include the size of the resource fork.” Interpreting that for modern macOS, that’s the size of the data, excluding extended attributes. So Precize then adds the total size of all the file’s extended attributes to give the final total from the file system.
The figures given for URL Keys are taken from URL resourceValues for fileSize
and totalFileSize
. Apple defines those as:
fileSize
is “the total file size, in bytes”totalFileSize
is “the total displayable size of the file, in bytes. The allocated size in bytes may include space used by metadata.”
and that’s as close to a total file size including extended attributes that macOS seems able to give. In this case, totalFileSize
includes around half the extended attributes, but not all of them, making it incorrect for just the data size, and incorrect for the total of data and extended attributes. Apple doesn’t explain how it chooses which to include, but it renders the figure of little or no use. Although for some reason, the Finder seems to believe it.
Over the last six years we have progressed from Get Info omitting extended attributes altogether, to including some of them apparently at random. Maybe in another six years, the Finder will prove more accurate.