public void Uncompress(ByteArray.CompressionAlgorithm algorithm) { this.Position = 0U; MemoryStream memoryStream = new MemoryStream(); byte[] buffer = new byte[1024]; DeflateStream deflateStream = algorithm == ByteArray.CompressionAlgorithm.Zlib ? (DeflateStream) new ZlibStream((Stream)this.MemoryStream, CompressionMode.Decompress, false) : new DeflateStream((Stream)this.MemoryStream, CompressionMode.Decompress, false); while (true) { int count = deflateStream.Read(buffer, 0, buffer.Length); if (count != 0) { memoryStream.Write(buffer, 0, count); } else { break; } } this.MemoryStream.Dispose(); this.MemoryStream = memoryStream; this.MemoryStream.Position = 0L; this._dataOutput = new DataOutput(new AmfWriter((Stream)this.MemoryStream, this._serializationContext)); this._dataInput = new DataInput(new AmfReader((Stream)this.MemoryStream, this._serializationContext)); }
public void Compress(ByteArray.CompressionAlgorithm algorithm) { byte[] array = this.MemoryStream.ToArray(); this.MemoryStream.Close(); MemoryStream memoryStream = new MemoryStream(); DeflateStream deflateStream = algorithm == ByteArray.CompressionAlgorithm.Zlib ? (DeflateStream) new ZlibStream((Stream)memoryStream, CompressionMode.Compress, true) : new DeflateStream((Stream)memoryStream, CompressionMode.Compress, true); using (deflateStream) deflateStream.Write(array, 0, array.Length); this.MemoryStream = memoryStream; this._dataOutput = new DataOutput(new AmfWriter((Stream)this.MemoryStream, this._serializationContext)); this._dataInput = new DataInput(new AmfReader((Stream)this.MemoryStream, this._serializationContext)); }