public static byte[] Decompress(byte[] data) { using (var input = new MemoryStream(data)) using (var decompressor = new ZInputStream(input)) { decompressor.CopyTo(input); return(input.ToArray()); } }
public static void DecryptTo(this Stream encryptedInputStream, Stream plaintextOutputStream, ICryptoTransform transform, bool isCompressed) { Exception savedExceptionIfCloseCausesException = null; try { if (encryptedInputStream == null) { throw new ArgumentNullException("encryptedInputStream"); } if (plaintextOutputStream == null) { throw new ArgumentNullException("plaintextOutputStream"); } if (transform == null) { throw new ArgumentNullException("transform"); } if (isCompressed) { using (Stream deflatedPlaintextStream = New <CryptoStreamBase>().Initialize(encryptedInputStream, transform, CryptoStreamMode.Read)) { using (Stream inflatedPlaintextStream = new ZInputStream(deflatedPlaintextStream)) { try { inflatedPlaintextStream.CopyTo(plaintextOutputStream); } catch (Exception ex) { savedExceptionIfCloseCausesException = ex; throw; } } } } else { using (Stream plainStream = New <CryptoStreamBase>().Initialize(encryptedInputStream, transform, CryptoStreamMode.Read)) { try { plainStream.CopyTo(plaintextOutputStream); } catch (Exception ex) { savedExceptionIfCloseCausesException = ex; throw; } } } } catch (Exception) { if (savedExceptionIfCloseCausesException != null) { throw savedExceptionIfCloseCausesException; } throw; } }