/// <summary> /// SharpZip½âѹËõ /// </summary> /// <param name="buffer"></param> /// <returns></returns> public static byte[] DecompressSharpZip(byte[] buffer) { if (buffer == null || buffer.Length == 0) { return buffer; } using (MemoryStream inStream = new MemoryStream(buffer)) { InflaterInputStream unCompressStream = new InflaterInputStream(inStream); MemoryStream outStream = new MemoryStream(); int mSize; Byte[] mWriteData = new Byte[4096]; while ((mSize = unCompressStream.Read(mWriteData, 0, mWriteData.Length)) > 0) { outStream.Write(mWriteData, 0, mSize); } unCompressStream.Close(); return outStream.ToArray(); } }
/// <summary> /// Creates an input stream reading a zip entry /// </summary> /// <param name="entryIndex">The index of the entry to obtain an input stream for.</param> /// <returns> /// An input <see cref="Stream"/> containing data for this <paramref name="entryIndex"/> /// </returns> /// <exception cref="ObjectDisposedException"> /// The ZipFile has already been closed /// </exception> /// <exception cref="SharpZip.Zip.ZipException"> /// The compression method for the entry is unknown /// </exception> /// <exception cref="IndexOutOfRangeException"> /// The entry is not found in the ZipFile /// </exception> public Stream GetInputStream(long entryIndex) { if ( isDisposed_ ) { throw new ObjectDisposedException("ZipFile"); } long start = LocateEntry(entries_[entryIndex]); CompressionMethod method = entries_[entryIndex].CompressionMethod; Stream result = new PartialInputStream(this, start, entries_[entryIndex].CompressedSize); if (entries_[entryIndex].IsCrypted == true) { #if NETCF_1_0 throw new ZipException("decryption not supported for Compact Framework 1.0"); #else result = CreateAndInitDecryptionStream(result, entries_[entryIndex]); if (result == null) { throw new ZipException("Unable to decrypt this entry"); } #endif } switch (method) { case CompressionMethod.Stored: // read as is. break; case CompressionMethod.Deflated: // No need to worry about ownership and closing as underlying stream close does nothing. result = new InflaterInputStream(result, new Inflater(true)); break; default: throw new ZipException("Unsupported compression method " + method); } return result; }