views:

101

answers:

2

My array is 140bytes. outArray is 512bytes... Not what i wanted. Also i dont know if i am encrypting properly. Is the code below correct? how do i fix this so outArray is the real size and not fixed with many trailing zeros?

        var compress = new SevenZipCompressor();
        compress.CompressionLevel = CompressionLevel.Ultra;
        compress.CompressionMethod = CompressionMethod.Lzma;
        compress.ZipEncryptionMethod = ZipEncryptionMethod.Aes256;
        var sIn = new MemoryStream(inArray);
        var sOut = new MemoryStream();
        compress.CompressStream(sIn, sOut, "a");
        byte[] outArray = sOut.GetBuffer();
+1  A: 

Many compression algorithms (I'm unfamiliar with the specific details for 7-zip) generate output with a minimum output size. 7-zip performs best on large input data sets, and 140 bytes is not "large". You might do better with something like gzip or lzo. What other compression algorithms have you tried?

Greg Hewgill
+3  A: 

You are getting the whole MemoryStream buffer, you need to use ToArray(),

  byte[] outArray = sOut.ToArray();

This will remove the trailing zeros but you may still get an array bigger than input. There is overhead with compression/encryption, which is probably bigger than 140 bytes.

ZZ Coder