12

Is it worth it for me to compress a 1000 byte file to a 300 byte file? or will the filesystem space consumption be the same?

I'm looking at storing 10k less than 4k files on my iphone and I'm curious if I'll see space saving by compressing them.

Thank you,

Carl

Carl Coryell-Martin
  • 3,410
  • 3
  • 26
  • 23
  • iPhone has 8GB+ space for your files. Do you really think that those few extra KBs you will save will give you any benefit? – RaYell Aug 22 '09 at 06:35
  • 1
    It's not necessarily always a space issue - some filesystems have better or worse performance depending on how the files stored get aligned with blocks and whether the filesystem performs tail packing. Especially with 10k+ files, the potential small savings per file can add up pretty quickly if the filesystem is configured correctly. – Tim Aug 22 '09 at 06:39
  • Why don't you just give it a try and share your experiences in an answer to your question? – Nikolai Ruhe Aug 22 '09 at 09:58
  • 1
    I'm getting to a proper test. As a side note Itunes will lie about how much free space is on your iphone. I've installed a 30MB application on an iPhone with 37MB of free space, then unpacked an 80MB database file. (It did take awhile though.) – Carl Coryell-Martin Aug 22 '09 at 14:16
  • how about combining your large number of tiny files into a smaller number of bigger files? then you could compress those if you wanted... – David Maymudes Aug 23 '09 at 17:07

1 Answers1

21

The iPhone uses an HFSX filesystem, with an 8k block size on the user partition:

int main(int argc, char *argv[]) {
  struct statfs *mntbufp = NULL;
  getmntinfo(&mntbufp, 0);

  unsigned i, count = 0;

  count = getmntinfo(&mntbufp, 0);
  for (i=0; i<count; i++)
  {
    char *volName = mntbufp[i].f_mntonname;
    printf("Volume %s blocksize: %lu\n", volName, mntbufp[i].f_bsize);
  }

  return 0;
}

returns

Volume / blocksize: 8192
Volume /dev blocksize: 512
Volume /private/var blocksize: 8192
Volume /Developer blocksize: 4096
Louis Gerbarg
  • 43,356
  • 8
  • 80
  • 90
  • exactly what I'm looking for, but get a compile error: Definition of 'struct statfs' must be imported from 'Darwin.sys.mount' before it is required. – horseshoe7 Aug 08 '14 at 08:00
  • add #include – hailuodev Feb 03 '16 at 02:40
  • 1
    Based on @Louis-Gerbarg answer, I wrote [simple app](https://github.com/MelnykTaras/FilesystemClusterSize) to print information about mounted volumes to console. BTW, on iPhone 5s iOS9 32Gb block size is 4 kb. I guess, it depends on storage size and file system type (HFS or APFS). – Terry Apr 21 '18 at 19:47