7zip compress network stream

前端 未结 2 1051
北恋
北恋 2021-01-06 13:13

I will like to compress a file before sending it through the network. I think the best approach is 7zip because it is free and open source.

How I use 7zip wi

2条回答
  •  花落未央
    2021-01-06 13:55

    CompressStream threw an exception. My code is as follows:

        public void TestCompress()
        {
            string fileToCompress = @"C:\Users\gary\Downloads\BD01.DAT";
            byte[] inputBytes = File.ReadAllBytes(fileToCompress);
            var inputStream = new MemoryStream(inputBytes);
    
            byte[] zipBytes = new byte[38000000];   // this memory size is large enough.
            MemoryStream outStream = new MemoryStream(zipBytes);
    
            string compressorEnginePath = @"C:\Engine\7z.dll";
            SevenZipCompressor.SetLibraryPath(compressorEnginePath);
    
            compressor = new SevenZip.SevenZipCompressor();
            compressor.CompressionLevel = CompressionLevel.Fast;
            compressor.CompressionMethod = CompressionMethod.Lzma2;
            compressor.CompressStream(inputStream, outputStream);
    
            inputStream.Close();
            outputStream.Close();
    

    The exception messages: Message: Test method Test7zip.UnitTest1.TestCompress threw exception: SevenZip.SevenZipException: The execution has failed due to the bug in the SevenZipSharp. Please report about it to http://sevenzipsharp.codeplex.com/WorkItem/List.aspx, post the release number and attach the archive

提交回复
热议问题