There is one dll and if we zip it on windows 10 and windows server 2012 using same code, it produces different size. Size difference is exactly 5 bytes. C# code is
private static void Zip()
{
var fileInfo = new FileInfo(@"C:\USB\adammigrate.dll");
using (Stream stream = File.Open(@"C:\USB\adammigrate.dll", FileMode.Open, FileAccess.Read, FileShare.Read))
using (var zipArchive = ZipFile.Open(@"C:\USB\adammigrate1.zip", ZipArchiveMode.Create))
{
var entry = zipArchive.CreateEntry("adammigrate.dll", CompressionLevel.NoCompression);
entry.LastWriteTime = fileInfo.LastWriteTime.ToUniversalTime();
using (Stream stream2 = entry.Open())
{
var buffer = new byte[BufferSize];
int numBytesRead;
while ((numBytesRead = stream.Read(buffer, 0, buffer.Length)) > 0)
{
stream2.Write(buffer, 0, numBytesRead);
}
}
}
}
Size on disk is same but actual size is differ by 5 bytes. PFA Zip Info for both the zip files.
The zip format is not guaranteed to have a single representation; it can be different sizes depending on specifics of the implementation (i.e. multiple encoding options are available, and it may or may not choose the absolute best one). The only important question is: does it unzip back to the original content? If it fails to unzip, then it is interesting. But being different sizes by itself doesn't mean anything.
If you want an absolute guarantee of getting the exact same zip output, you'll have to find an implementation that offers output stability as a documented feature; the implementation you're using clearly doesn't offer that. Usually tools like zip want to retain the ability to quietly improve their choices for your benefit between versions (and sometimes it might try to make things better generally, with the side-effect that sometimes it makes it worse).
If you were anticipating always getting the exact same bytes back: then zip is probably not an appropriate file format for you, unless you only compare the sizes and contents of the internal payloads (i.e. what they would be once decompressed), not the zip file itself.