Is DeflateStream = .zip format?

G

Grok

Trying to zip/unzip files from VB.NET 2005 with 2.0 .NET Framework ...
but the file created "SampleFile.zip" is not a readable zip file.
(Using GZipStream works correctly to produce a readable .gz file)
How do I properly create a .zip file without 3rd-party lib?

Dim sourceFile As FileStream =
File.OpenRead("c:\temp\SampleFile.chm")
Dim destFile As FileStream =
File.Create("c:\temp\SampleFile.zip")

'wrap dest stream with compression stream
Dim compStream As New DeflateStream(destFile,
CompressionMode.Compress)

'copy data from source stream to destination stream
Dim theByte As Integer = sourceFile.ReadByte()
While theByte <> -1
compStream.WriteByte(CType(theByte, Byte))
theByte = sourceFile.ReadByte()
End While
compStream.Flush()

'clean up
sourceFile.Close()
compStream.Close()
destFile.Close()
 
A

Andrew Morton

Grok said:
Trying to zip/unzip files from VB.NET 2005 with 2.0 .NET Framework ...
but the file created "SampleFile.zip" is not a readable zip file.
(Using GZipStream works correctly to produce a readable .gz file)
How do I properly create a .zip file without 3rd-party lib?

It sounds like what you're after is a zip /archive/ rather than a single
file stored with compression; what do you have against third-party
libraries? For example, SharpZipLib is free and easy to use. Even paying for
one is likely to be cheaper than developing your own.

If you do want to write your own, you can find file formats at
www.wotsit.org.

Andrew
 
H

Herfried K. Wagner [MVP]

Grok said:
Yes, and Windows includes the functionality intrinsically as a shell
extension, so I thought it natural it would be part of the FCL. Based
on the two responses here, and all my googling, this is not the case.

I specifically wanted to make you aware of these resources:

..NET 2.0 contains ZIP support in the namespace 'System.IO.Compression':

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

Using GZipStream for Compression in .NET [Brian Grunkemeyer]
<URL:http://blogs.msdn.com/bclteam/archive/2005/06/15/429542.aspx>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top