VB.Net CompressFiles or CompressStream

Apr 2, 2010 at 4:42 PM
Edited Apr 5, 2010 at 1:46 PM

Hello I am using the library in VB.Net and am having issues with CompressFiles and CompressStream. CompressDirectory works fine. CompressFiles and CompressStream just hang.

Please see code sample below. Any help would be much appreciated.


Dim cmp As SevenZipCompressor = New SevenZipCompressor()

cmp.ArchiveFormat = OutArchiveFormat.SevenZip

cmp.CompressionMethod = SevenZip.CompressionMethod.Default

cmp.CompressionMode = SevenZip.CompressionMode.Create

cmp.CompressionLevel = CompressionLevel.High

cmp.VolumeSize = 0

cmp.CompressDirectory("C:\MDT\VSI_DataModule\DAOSample", "C:\MDT\VSI_DataModule\DOASample.7Z") 'cmp.CompressFiles(OutFile, Infile)

cmp.CompressStream(File.OpenRead(Infile), File.Create(OutFile))

Apr 5, 2010 at 1:45 PM

I tested it further. If I compress the directory first and within the same procedure call, I then compress the file or stream it works. If I comment out the code to compress the directory, and only compress file or stram, the process hangs.

Any info on what I am doing wrong would be greatly appreciated.

Apr 12, 2010 at 5:30 PM

These lines of code

cmp.ArchiveFormat = OutArchiveFormat.SevenZip cmp.CompressionMethod = SevenZip.CompressionMethod.Default cmp.CompressionMode = SevenZip.CompressionMode.Create cmp.VolumeSize = 0

can be skipped as they are initialized to the defaults.

It doesn't hang. Strange. You should give the detailed description and the complete code context.


Aug 13, 2010 at 2:54 PM

The same problem is happening to me ...

When the first compact works perfectly, but to compress the second time the process hangs.

Important: If I decrease the size of content that is compressed works for all cases.


Public Function Zidane(ByVal data As Byte()) As Byte()
		Dim comp As SevenZipCompressor = New SevenZipCompressor()
		Dim bytes As Byte()

		Using mIn As MemoryStream = New MemoryStream(data)
			Using mOut As MemoryStream = New MemoryStream()
				comp.CompressionLevel = CompressionLevel.Ultra
				comp.CompressionMethod = CompressionMethod.Lzma
				comp.CompressStream(mIn, mOut)
				bytes = mOut.ToArray()
			End Using
		End Using
		Return bytes
	Catch ex As Exception
		Throw ex
	End Try
End Function

Aug 13, 2010 at 6:34 PM

I put the 7z source in my solution and debug. I found the point that there is a crash, but...

When the system exits the method "Read" (class StreamWrapper) the execution goes to a black hole and is never seen again. Lose the VC IDE tool to help.

Any idea?

public int Read(byte[] data, uint size)
	int readCount = 0;
	if (BaseStream != null)
		readCount = BaseStream.Read(data, 0, (int) size);
		if (readCount > 0)
			OnBytesRead(new IntEventArgs(readCount));
	return readCount;
} <<<