internal static byte[] Deflate(byte[] buffer, int sizeCompressed, int sizeDecompressed) { using (RecyclableMemoryStream tmp = new RecyclableMemoryStream()) { BnSDatArchive.UncompressBuffer(buffer, tmp); if (tmp.Length != sizeDecompressed) { byte[] tmp2 = new byte[sizeDecompressed]; if (tmp.Length > sizeDecompressed) { Array.Copy(tmp.GetBuffer(), 0, tmp2, 0, sizeDecompressed); } else { Array.Copy(tmp.GetBuffer(), 0, tmp2, 0, tmp.Length); } return(tmp2); } else { return(tmp.ToArray()); } } }
internal static byte[] UncompressBuffer(byte[] compressed) { using (var input = new MemoryStream(compressed)) using (var output = new RecyclableMemoryStream()) using (var decompressor = new ZlibStream(input, CompressionMode.Decompress)) using (Leayal.ByteBuffer buffer = new Leayal.ByteBuffer(1024)) { int read = decompressor.Read(buffer, 0, buffer.Length); while (read > 0) { output.Write(buffer, 0, read); read = decompressor.Read(buffer, 0, buffer.Length); } return(output.ToArray()); } }
public byte[] ToArray() { ThrowIfDisposed(); return(m_stream.ToArray()); }