DeflateStream works for compression, but not decompression

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The compression part of this code works fine for me, but the decompression
part of this code does not. The output file from that is the same as the
compressed file.
What is wrong with my code?
Thanks,
Jon
'compression starts here
Dim src As FileStream = File.OpenRead(Fn)
Dim dst As FileStream = File.Create(Ofn)
Dim cmp As New DeflateStream(dst, CompressionMode.Compress)

Dim ba(src.Length) As Byte
src.Read(ba, 0, src.Length)
cmp.Write(ba, 0, src.Length)
cmp.Close()
src.Close()
dst.Close()
'decompression starts here
src = File.OpenRead(Ofn)
Dim slen As Integer = src.Length
Dim ba1(slen * 2) As Byte

cmp = New DeflateStream(src, CompressionMode.Decompress)
cmp.Read(ba1, 0, slen)
dst = File.Create(txt)
dst.Write(ba1, 0, slen)

cmp.Close()
src.Close()
dst.Close()
 
Did you find an answer to this? Are you still looking? I saw something
online about a problem with this, so if you're still looking, let me know
and I'll track down and post the url.

Robin S.
 
Did you find an answer to this? Are you still looking? I saw something
online about a problem with this, so if you're still looking, let me know
and I'll track down and post the url.
Thank you. No, I never found out why this code did not work. I would
appreciate that url.

Jon
 
Here's the info I have tucked away about doing compression in .Net.


According to this article, you can do compression with the .Net
System.IO.Compression class, although there are some anomalies with the
DeflateStream class (see the bottom of the page, in red).

http://blogs.msdn.com/dotnetinterop/archive/2006/04/05/.NET-System.IO.Compression-and-zip-files.aspx

Another article:

http://www.windowsdevcenter.com/pub/a/windows/2006/09/12/using-data-compression-in-net-20.html

Here is an OpenSource project available here:
http://www.icsharpcode.net/OpenSource/SharpZipLib/

Hope this helps.
Robin S.
-----------------------------------
 
Back
Top