Sign up ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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?

share|improve this question

closed as not a real question by Mircea Vutcovici, Michael Hampton, John Gardeniers, Magellan, Ward Nov 11 '12 at 6:10

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

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 '12 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 '12 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. – Kevin Johnson Aug 23 '12 at 3:19
What is "Text-based storage"? – Alan Curry Aug 23 '12 at 3:19
@AlanCurry, If you must know, I was going to try it out with Google Docs. – Kevin Johnson Aug 23 '12 at 3:23

1 Answer 1

up vote 1 down vote accepted

Just compress before encoding.

  $ wc -c < /bin/ls
  $ < /bin/ls base64 | wc -c
  $ xz < /bin/ls | base64 | wc -c

(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.

share|improve this answer
Trying to use more of them leads to things like yEnc – Alan Curry Aug 25 '12 at 20:58

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