Finder reports empty files as having 286 bytes

Discussion in 'OS X Mountain Lion (10.8)' started by RoyG, Jul 16, 2013.

  1. RoyG macrumors newbie

    Jul 24, 2011
    All right... This is a really weird problem. I am writing a software parsing log files in CSV format from several different types of logs into one file ordered by date and time and lots of other formatting. Files that are less than standard is used as input and the plan is to have properly formatted CSV as output.

    This is not very complicated to do and everything is working all right, except for the bug I found making the whole thing go in an endless loop when you feed an empty file. Probably an easy fix.

    For the time being, I am feeding the files manually, at compile time. I am skipping all empty files because I really don't need to parse those. So I pick the files that Finder tells me is not empty.

    Suddenly my software hangs in an endless loop on something that seems like a valid file. I open the file in an text editor, but the editor insists the file is empty. Finder says there is 286 bytes.

    Usually I would think that the text editor was wrong and not the operating system, so I did some more investigation. Hex fiend is a Hex editor, it loads binary files, shows whats inside even if there are only 286 spaces you will see it. Surprise! The file really IS 0 bytes! (see my attached picture)


    So... What is going on? Why is Finder reporting empty files as having 286 bytes?
  2. simsaladimbamba

    Nov 28, 2010
    While the file may have no visible content, it still needs some storage capacity to store the file name and the header, thus 286 bytes seems about right, though it will probably take away 4 KB due to the sector size.

    I just tried it with TextEdit and saved an empty document and it reported as being 178 bytes big, but due to sectors it takes away 4 KB of actual storage capacity.
  3. RoyG thread starter macrumors newbie

    Jul 24, 2011
    I tried a little experiment myself...

    First I made a file with Text Edit like you did. But Text Edit only saves rich text files that are never really empty, even though you haven't written anything. This file really contains 178 bytes. (See image below.)

    Then I made a TXT file using Smultron, which is a pure text editor. This time the document truly was zero bytes, which is what I would expect in the other case too.


    So now I am going to make a Objective C program on the original empty files to see what that is reporting... (I will post an update on this in a few minutes.)
  4. RoyG thread starter macrumors newbie

    Jul 24, 2011
    I made a little Objective C program to test the file size. It turns out Finder really is reporting the wrong file size.


    The first file is the one that Finder reports as being 286 bytes. It really IS 0 bytes. The second file should be the file directly above or below in the list in the first picture. I haven't checked if those files is being reported correctly. I am not actually expecting Finder to be 100% exact when it shows Kbytes, Mbytes etc. but bytes should always be correct.
  5. RoyG thread starter macrumors newbie

    Jul 24, 2011
    I just wanted to comment on what you are saying about storage capacity. If you see the middle part of the first picture I posted, you will see the following text:

    Size 286 bytes (4 kb on disk)

    The first number is the size of the file. The part in parentheses is the storage capacity, as you are mentioning correctly, is because of the sector size. This has to do with how the file system works, and all files are multiples of the sector size (4 kb in this example)

    The size of the file should still be ZERO, not 286.

    I had a theory that something went bananas inside Finder so I force restarted Finder. That didn't change anything.

    Next I am going to reboot the whole machine.

    If that doesn't help, I will check the file system.

    If that doesn't help, I really haven't got a clue...
  6. RoyG thread starter macrumors newbie

    Jul 24, 2011
    This will be my last post about this subject. I think I have some sort of semi explanation to what is going on. (Or maybe even the whole explanation.)

    These files have been a round trip to Google Drive Storage and back to my machine. It seems there have been added some metadata from Google to my files. If I look up "Show Info" on the file, there is a new field under "More info" that says "Where From" giving the whole URL to where on Google Drive this file was downloaded from.

    It is hard to test if this is the case, because you can't easily set these fields yourself. (Of course you can, but I don't know of any software yet.)

    Anyway: Counting the metadata into the size of the file content is WRONG WRONG WRONG, Apple!!! (Given that actually is the case.)

    I did the following experiment:
    I formatted a memory stick to MS DOS FAT partition.
    Then I copied the file into the memory stick.
    There is some magic going on here since that didn't help. 16 bit FAT has not much metadata capabilities so it seems Finder keeps track somehow anyway.

    Next part of the experiment was to check the file size on a MS Windows machine. File size is reported as 0 bytes. (Hallelujah!)

    I copied the file to the windows machine, reformatted the memory stick, copied the file back. THIS MUST SURELY HAVE REMOVED THE METADATA.

    Checking the file size on my Mac... ZERO BYTES!!! (Hallelujah again!!!)

    It definitely must have something to do with metadata...

    Apple, please stop confusing people with counting the metadata into the file contents! It is plain WRONG!

Share This Page