Re: string to byte[] back to string + Compression Failed!

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Hi Jeremy,

Your problem is converting the compressed byte[] to string. After the compression a string can't hold the data the byte[] holds and you lose lots of data causing an exception when you try to decompress it.

Having Compress return a byte[] and Decompress take a byte[] will solve your problem. If you need the byte[] to be represented as string you can use Base64.

[DecompressString]
byte[] bData = Convert.FromBase64String(in_string);

[CompressString]
out_string = Convert.ToBase64String(compressed_data);


--
Happy Coding!
Morten Wennevik [C# MVP]
.



Relevant Pages

  • Re: =?iso-8859-1?q?Re:_Kolmorgorov_Complexity_and_Kim_=D8yhus?=
    ... >>>of the string. ... >> universal computing device, say an universal Turing machine, which IS ... K.C. is defined to require an universal computer, ... >These are different forms of potential compression. ...
    (talk.origins)
  • =?iso-8859-1?q?Re:_Kolmorgorov_Complexity_and_Kim_=D8yhus?=
    ... >>of the string. ... These are different forms of potential compression. ... >>functional system may not be able to sustain such sequence compression ... Chaos theory is about DETERMINISTIC systems which amplify small ...
    (talk.origins)
  • Re: Attention Sean - question about CSI
    ... Maybe the degree of compression can serve as a measure ... If I am allowed to choose the compression algorithm *after* ... which compresses that string to a single bit. ... If you are allowed to transmit the data separately, ...
    (talk.origins)
  • Re: Just for fun...
    ... complexity in practical scenarios... ... corresponding complexities for a given string can differ at most by a constant ... When I first learned about the concept of compression, ... surprise in the questions/issues being discussed, ...
    (comp.lang.ruby)
  • Re: compression
    ... years has had compression on it.. ... It can vary attack time.. ... It gives you a more even output from string to string.. ... without digging entirely into the tubes.. ...
    (alt.guitar)