public void CloseEntry()
{
if (crc == null) {
throw new InvalidOperationException("Closed");
}
if (entry == null) {
return;
}
if (method == (int)CompressionMethod.Deflated) {
if ((flags & 8) != 0) {
// We don't know how much we must skip, read until end.
byte[] tmp = new byte[4096];
// Read will close this entry
while (Read(tmp, 0, tmp.Length) > 0) {
}
return;
}
csize -= inf.TotalIn;
inputBuffer.Available += inf.RemainingInput;
}
if ((inputBuffer.Available > csize) && (csize >= 0)) {
inputBuffer.Available = (int)((long)inputBuffer.Available - csize);
} else {
csize -= inputBuffer.Available;
inputBuffer.Available = 0;
while (csize != 0) {
long skipped = Skip(csize);
if (skipped <= 0) {
throw new ZipException("Zip archive ends early.");
}
csize -= skipped;
}
}
CompleteCloseEntry(false);
}
/// ------------------------------------------------------------------------------------ /// <summary> /// Unzip a byte array and return unpacked data /// </summary> /// <param name="data">Byte array containing data to be unzipped</param> /// <returns>unpacked data</returns> /// ------------------------------------------------------------------------------------ public static byte[] UnpackData(byte[] data) { if (data == null) return null; try { MemoryStream memStream = new MemoryStream(data); ZipInputStream zipStream = new ZipInputStream(memStream); zipStream.GetNextEntry(); MemoryStream streamWriter = new MemoryStream(); int size = 2048; byte[] dat = new byte[2048]; while (true) { size = zipStream.Read(dat, 0, dat.Length); if (size > 0) { streamWriter.Write(dat, 0, size); } else { break; } } streamWriter.Close(); zipStream.CloseEntry();