c# - GZipStream makes my text bigger than original -


there post in here compress , decompress string in c# compressing string in c#.

i've implement same code myself returned text twice mine :o

i've tried on json size 87 this:

{"g":"82f88ff5-4143-46ef-86cc-a19910f4a6b5","u":"df39e3c7-ffd3-4829-a9cd-27bfcbd4403a"}

the result 168

h4siaaaaaaaeac2nuq6dibqe5yx8l0qfqfqcnqahqkcxahr3jsaq3tyyfcuxwkpeamhi0bf9ycasgvw6pslua5qwmifykvbpycdj3gube4ghet+txzzm7xrj6d7z3u/w8896dvvpd5rmbcaa3k1k25m88ompcjdew64aaaa=

i've changed unicode ascii result still big (128)

h4siaaaaaaaeaa3kyxgamagfwf44y0w+jaebsailicsvccfedc/70eunayeq0fiyvja+wdoj2lnzthdvs9fb918xqu0ag4h1vy3gbrg4jimysyrvp/cdp8eze1caaaa=

public static string compress(this string s) {     var bytes = encoding.ascii.getbytes(s);     using (var msi = new memorystream(bytes))     using (var mso = new memorystream())     {         using (var gs = new gzipstream(mso, compressionmode.compress))         {            msi.copyto(gs);          }         return convert.tobase64string(mso.toarray());     } } 

gzip not compression complete file format - means adds additional structures can neglected regarding size. if compressing small strings can blow overall gzip stream.

the standard gzip header example has 10 bytes , it's footer 8 bytes long.

therefore take gzip compressed result in raw format (not bloated base64 encoded one) see has 95 bytes.

therefore 18 bytes header , hooter make 20% of output!


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -