private byte[] ZipUncompressStream2(byte[] bData) { Chilkat.Zip zip = new Chilkat.Zip(); zip.UnlockComponent("HAFSJOZIP_5KkXdE9n9Zpu"); bool success = zip.OpenFromMemory(bData); Chilkat.ZipEntry entry = zip.FirstEntry(); return(entry.Inflate()); }
/* * private byte[] ZipCompressStream(byte[] bData, string fileName, DateTime fileDate) * { * MemoryStream streamIm = new MemoryStream(bData); * MemoryStream streamOut = new MemoryStream(); * ZipOutputStream zipOut = new ZipOutputStream(streamOut); * ZipEntry entry = new ZipEntry(fileName); * entry.DateTime = fileDate; * entry.Size = streamIm.Length; * zipOut.PutNextEntry(entry); * zipOut.Write(streamIm.ToArray(), 0, (int)streamIm.Length); * * zipOut.Finish(); * zipOut.IsStreamOwner = false; * zipOut.Close(); * return streamOut.ToArray(); * } * * private byte[] ZipUncompressStream(byte[] bData) * { * MemoryStream streamIn = new MemoryStream(bData); * MemoryStream streamOut = new MemoryStream(); * ZipInputStream zipIn = new ZipInputStream(streamIn); * ZipEntry entry; * entry = zipIn.GetNextEntry(); * long size = entry.Size; * byte[] buffer = new byte[size]; * while (true) * { * size = zipIn.Read(buffer, 0, buffer.Length); * if (size > 0) streamOut.Write(buffer, 0, (int)size); * else break; * } * streamOut.Flush(); * return streamOut.ToArray(); * } */ private byte[] ZipCompressStream2(byte[] bData, string fileName, DateTime fileDate) { Chilkat.Zip zip = new Chilkat.Zip(); zip.UnlockComponent("HAFSJOZIP_5KkXdE9n9Zpu"); zip.NewZip("notUsed.zip"); Chilkat.ZipEntry entry = null; entry = zip.AppendData(fileName, bData); entry.FileDateTime = fileDate; return(zip.WriteToMemory()); }
private static void CheckZipFile(Stream stream, string[] filestocheckexist, bool filenameonly, string password, bool aes128) { List<string> zipFiles = new List<string>(); using (Chilkat.Zip zip = new Chilkat.Zip()) { zip.UnlockComponent("WRKSHRZIP_YrPEVwzmlDsV"); zip.SetPassword(password); byte[] zipData = StreamUtils.SafeButUnpleasantReadAllStreamIntoByteArray(stream); if (!string.IsNullOrEmpty(password) && !aes128) { string sTempFile = Path.GetTempFileName(); System.IO.File.WriteAllBytes(sTempFile, zipData); bool bPwdProtected = zip.IsPasswordProtected(sTempFile); System.IO.File.Delete(sTempFile); Assert.IsTrue(bPwdProtected); } if (!zip.OpenFromMemory(zipData)) throw new System.Exception(zip.LastErrorText); Assert.AreEqual(zip.Encryption, aes128 ? 4 : 0); Assert.AreEqual(zip.EncryptKeyLength, aes128 ? 128 : 0); for (int index = 0; index < zip.NumEntries; ++index) { using (Chilkat.ZipEntry zipEntry = zip.GetEntryByIndex(index)) { if (null == zipEntry) break; zipFiles.Add(filenameonly ? Path.GetFileName(zipEntry.FileName) : zipEntry.FileName); } } } foreach (string file in filestocheckexist) { Assert.IsTrue(zipFiles.Contains(file), "Did not find expected file inside zip : " + file); } stream.Close(); }