.NET 4.5 ZipFile class not producing consistent files

Viewed 294

Maybe I am just not understanding Zip files... Here is what I have. I am using code pasted below to zip my java workspace and push it to a network drive. The intent is that I will have this run on PC login. I have all of my java windows closed, I run the tool twice. I produces 2 zips of the same byte length but different MD5s, according to .NET and a linux system that I copied them to.

However, when I manually use 7zip to create a zip file from my java directory, I do it 2 separate times and the files have the same MD5.

Can any one either verify this issue or provide some insight into what could cause this? To my understanding zip files should be repeatable, there is no like random Seed or anything in the algorithm. This code was compiled with VS2012 and with the System.IO.Compression.FileSystem stuff linked in assembly.

 Public Sub New(sourceDir As String, baseName As String)
        s = sourceDir
        t = t + baseName + ".zip"
        ZipFile.CreateFromDirectory(s, t, Compression.CompressionLevel.NoCompression, False)
        Dim stream As IO.FileStream = IO.File.OpenRead(t)
        Dim md5 As System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
        hash = BitConverter.ToString(md5.ComputeHash(stream))
        md5.Dispose()
        stream.Close()
        Dim file As New System.IO.FileInfo(t)
        fname = baseName + "." + hash + ".zip"
        t = file.DirectoryName + "\" + fname
        file.MoveTo(t)
    End Sub
1 Answers
Related