private byte[] GetDeflatedData(bool force = false) { if (!IsCompressed || force) { using (var dataStream = GetDataStream()) { return(Zlib.Compress(dataStream, GetDeflateLevel())); } } return(GetData()); }
private byte[] GetInflatedData(bool force = false) { if (IsCompressed || force) { using (var dataStream = GetDataStream()) { var decompressedData = Zlib.Decompress(dataStream, OriginalSize); if (decompressedData.Length != OriginalSize) { throw new IOException("Inflated size did not match original size"); } return(decompressedData); } } return(GetData()); }
public Stream GetContentStream(bool extract, bool force = false) { if (extract) { if (OriginalSize == 0) { return(null); } if (IsCompressed || force) { return(Zlib.DecompressStream(GetDataStream(), OriginalSize)); } } else { if (!IsCompressed || force) { return(Zlib.CompressStream(GetDataStream(), GetDeflateLevel())); } } return(GetDataStream()); }