c# - I want to compress a byte[] and return a byte[] -


i want write method in c# takes byte[] , compress byte[], can find libraries compress directory directory (the zipfile library).

is possible using .net platform?

is possible using .net platform?

sure - that's system.io.compression namespace for. example, use gzipstream class. use memorystream receive compressed data, , can call toarray afterwards.

sample code (untested):

public static byte[] compress(byte[] data) {     using (var output = new memorystream())     {         using (var compression = new gzipstream(output, compressionmode.compress))         {             compression.write(data, 0, data.length);         }         return output.toarray();     } }  public static byte[] compress(byte[] data) {     using (var output = new memorystream())     {         using (var compression = new gzipstream(output, compressionmode.decompress))         {             compression.write(data, 0, data.length);         }         return output.toarray();     } } 

you use deflatestream alternative compression form.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -