File compression routines in C, adapted iOS/Nimrod