Another convenient method is Base64 encoding used extensively by browsers as a standard format. This eliminates problematic control characters that can still be recovered during the decoding process, so you get a file that is exactly the expected format. It's not compression and i fact increases file size by 1/3 or so, but problematic characters are eliminated and reduced to A-Z, a-z, 0-9, / and *.