i compress an xml file using some compression technique (e.g. bzip2). i check the size of the compressed data in memory. then i write this compressed data into a file. more data gets written into the file than was intended. the size of the file shows that it has more data than size of the compressed data in memory. e.g. length of string in memory: 13k write this string into a file, its size is reported as 20k in the file. read the contents of this file into memory, and check the size, it shows 13k! this doesn't happen to original data that has not been compressed. also, if i encode the compressed file, then it doesnt show this problem. note that when the compressed file is encoded, it no longer remains binary data. my guess is that this has something to do with binary data since compression produces binary data. i want to keep the compressed data as it is, even when i write it into the file i want it to be exactly the same as it is in memory. maybe i am missing something very fundamental. any pointers/solution will really help. thanks.

In reply to binary data metamorphosis? by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.