Open romerod opened 4 years ago
I would like to merge two zip files without decompressing/recompressing and decrypting/encrypting.
The following spike code does what I want:
var addEntryMethod = typeof(ZipFile).GetMethod("InternalAddEntry", BindingFlags.NonPublic | BindingFlags.Instance);
using (var zip1 = ZipFile.Read(stream1)) using (var zip2 = ZipFile.Read(stream2)) { foreach (var entry in zip2.ToArray()) { entry.FileName = $@"zip2/{entry.FileName}"; addEntryMethod.Invoke(zip1, new object[] { entry.FileName, entry }); //zip1.InternalAddEntry(entry.FileName, entry); }
zip1.Save(@"C:\temp\merged.zip");
}
I would like to merge two zip files without decompressing/recompressing and decrypting/encrypting.
The following spike code does what I want:
var addEntryMethod = typeof(ZipFile).GetMethod("InternalAddEntry", BindingFlags.NonPublic | BindingFlags.Instance);
using (var zip1 = ZipFile.Read(stream1)) using (var zip2 = ZipFile.Read(stream2)) { foreach (var entry in zip2.ToArray()) { entry.FileName = $@"zip2/{entry.FileName}"; addEntryMethod.Invoke(zip1, new object[] { entry.FileName, entry }); //zip1.InternalAddEntry(entry.FileName, entry); }
}