-1

I'm trying to use the command base64 somefile.ext to covert files to text. The only problem is that the file size increases by 35%, and that becomes unacceptable for my larger files. I suspect that the files could be encoded in a way that makes their size smaller. Currently the encoding of the outputted file is us-ascii.

Is there an encoding that would make for a smaller file size?

10
  • It's not clear what are the requirement. Note that base64 is usually used to represent binary files in an ASCII string format so it will always use extra space.
    – golja
    Aug 23, 2012 at 2:20
  • It all depends on how far you're willing to stretch the definition of "text" (i.e. why are you doing it) and how standardized you want the format to be.
    – Alan Curry
    Aug 23, 2012 at 2:39
  • @AlanCurry: I'm doing it so that I can store the binary file in text-based storage. @golja: But ASCII also includes characters like null and CR, but to my observations base64 doesn't return any of those characters. Aug 23, 2012 at 3:19
  • What is "Text-based storage"?
    – Alan Curry
    Aug 23, 2012 at 3:19
  • @AlanCurry, If you must know, I was going to try it out with Google Docs. Aug 23, 2012 at 3:23

1 Answer 1

1

Just compress before encoding.

  $ wc -c < /bin/ls
  114024
  $ < /bin/ls base64 | wc -c
  154033
  $ xz < /bin/ls | base64 | wc -c
  59878

(you can use, gzip, bzip2 or any compressor you want, but need to remember to uncompress on the receiving end)

There aren't many printable ascii characters. base64 uses 64 of them, which means 6bits of input make 8 bits of output. There aren't many more you can use.

1
  • Trying to use more of them leads to things like yEnc
    – Alan Curry
    Aug 25, 2012 at 20:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.