0 Replies - 339 Views - Last Post: 21 July 2014 - 02:15 AM Rate Topic: -----

#1 Ayoka  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 05-July 13

50 % Compression of byte or base64String

Posted 21 July 2014 - 02:15 AM

Hi Forum,

I want to achieve 50% reduction/ compression of these files.

Kindly help, any suggestion or solution will be appreciated.

I have tried
 public static string Compress(byte[] buffer)
        {
          
           // byte[] buffer = Encoding.UTF8.GetBytes(text);
           // byte[] buffer = Convert.FromBase64String(text);
            MemoryStream ms = new MemoryStream();
            using (GZipStream zip = new GZipStream(ms, CompressionMode.Compress, true))
            {
                zip.Write(buffer, 0, buffer.Length);
            }

            ms.Position = 0;
            MemoryStream outStream = new MemoryStream();

            byte[] compressed = new byte[ms.Length];
            ms.Read(compressed, 0, compressed.Length);

            byte[] gzBuffer = new byte[compressed.Length + 4];
            System.Buffer.BlockCopy(compressed, 0, gzBuffer, 4, compressed.Length);
            System.Buffer.BlockCopy(BitConverter.GetBytes(buffer.Length), 0, gzBuffer, 0, 4);
            return Convert.ToBase64String(gzBuffer);
        }


but no satisfactory result.

Sorry the forum do not permit upload of binary file.

Attached File(s)


This post has been edited by modi123_1: 21 July 2014 - 07:06 AM
Reason for edit:: please use the 'code' button in the editor


Is This A Good Question/Topic? 0
  • +

Page 1 of 1