.NET 4.5的ZipFile类不能产生一致的文件 [英] .NET 4.5 ZipFile class not producing consistent files

查看:137
本文介绍了.NET 4.5的ZipFile类不能产生一致的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

也许我只是不理解的Zip文件?以下是我有。我使用code粘贴下面来压缩我的java工作区,并将其推到网络驱动器。这样做的目的是,我会对计算机登录本次运行。我有我的所有的Java窗口关闭,我运行该工具的两倍。我产生2拉链相同的字节长度,但不同的MD5s,根据.NET和Linux系统,我将其复制到。

然而,当我用手动来7zip的从我的Java目录下创建一个zip文件,我这样做是2个独立的时间和文件具有相同的MD5。

任何一个可以或者验证这个问题或提供一些见解,这是什么原因?据我了解的zip文件应该是可重复的,还有就是算法中没有像随机种子什么的。 这code用VS2012,并与System.IO.Com pression.FileSystem的东西,在装配连接编译。

 的Public Sub New(sourceDir作为字符串,baseName的作为字符串)
        S = sourceDir
        T = T + + baseName的.ZIP
        ZipFile.CreateFromDirectory(S,T,COM pression.Com pressionLevel.NoCom pression,FALSE)
        昏暗的流作为IO.FileStream = IO.File.OpenRead(T)
        昏暗MD5作为System.Security.Cryptography.MD5 = System.Security.Cryptography.MD5.Create()
        哈希= BitConverter.ToString(md5.ComputeHash(流))
        md5.Dispose()
        stream.Close()
        昏暗的文件是新System.IO.FileInfo(T)
        FNAME = + baseName的。 +散+.ZIP
        T = file.DirectoryName +\+ FNAME
        file.MoveTo(T)
    结束小组
 

解决方案

猜测的一点,但是拉链头规格包括的 文件的最后修改日期/时间 。最有可能的,这是被设置为文件的创建时间,这将是在两个试验之间不同。

这将是很容易为你检查,如果这是一个二进制文件编辑器的情况下。

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

解决方案

A bit of a guess, but the Zip header spec includes a fields for File last modification date/time. Most likely this is being set to the file creation time, which will be different between the two runs.

It would be easy enough for you to check if this is the case with a binary file editor.

这篇关于.NET 4.5的ZipFile类不能产生一致的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆