/// <summary> /// Puts the next header in a predefined order /// </summary> /// <param name="entry"> /// the ZipEntry which contains all the information /// </param> private void PutNextHeader(ZipEntry entry) { WriteLeInt32(entry.Size); //REcord the offset to write proper CRC and compressed size offset = baseStream.Position; WriteLeInt32(entry.CompressedSize); WriteBytes(entry.GetCrc()); WriteLeInt32(entry.DosTime); WriteLeInt16(entry.NameLength); byte[] names = ConvertToArray(entry.Name); baseStream.Write(names, 0, names.Length); }
/// <summary> /// Writes the uncompressed data into the filename in the /// entry. It instantiates a memory stream which will serve /// as a temp store and decompresses it using Gzip Stream or /// Deflate stream /// </summary> private void WriteUncompressedFile(ZipEntry entry, string completePath) { MemoryStream ms = new MemoryStream(); try { byte[] b = new byte[entry.CompressedSize]; baseStream.Read(b, 0, (int)entry.CompressedSize); if (CheckCRC(entry.GetCrc(), b)) ms.Write(b, 0, b.Length); ms.Seek(0, SeekOrigin.Begin); if (method == ZipConstants.DEFLATE) zipStream = new DeflateStream(ms, CompressionMode.Decompress, false); else if (method == ZipConstants.GZIP) zipStream = new GZipStream(ms, CompressionMode.Decompress, false); int index = entry.Name.LastIndexOf(ZipConstants.BackSlash); string name = completePath + entry.Name.Substring(index + 1); FileStream rewrite = new FileStream(name, FileMode.Create); b = new byte[entry.Size]; zipStream.Read(b, 0, (int)entry.Size); rewrite.Write(b, 0, (int)entry.Size); rewrite.Close(); } finally { zipStream.Close(); ms.Close(); } }