/// <summary> /// Sends data asynchronously /// </summary> public virtual void Write(Stream stream) { if (_isClosing) { OnError(new SocketException((int)SocketError.Shutdown)); } //This can result in OOM //A neat improvement would be to write this sync in small buffers when buffer.length > X var buffer = Utils.ReadAllBytes(stream, 0); if (_sendSocketEvent != null) { _sendSocketEvent.SetBuffer(buffer, 0, buffer.Length); bool willRaiseEvent = false; try { willRaiseEvent = _socket.SendAsync(_sendSocketEvent); } catch (Exception ex) { OnError(ex); } if (!willRaiseEvent) { OnSendCompleted(this, _sendSocketEvent); } } else { _socketStream.BeginWrite(buffer, 0, buffer.Length, new AsyncCallback(OnSendStreamCallback), null); } }
public Stream Decompress(Stream stream) { var buffer = Utils.ReadAllBytes(stream, 0); var outputLengthBytes = new byte[4]; Buffer.BlockCopy(buffer, 0, outputLengthBytes, 0, 4); Array.Reverse(outputLengthBytes); var outputLength = BitConverter.ToInt32(outputLengthBytes, 0); var decompressStream = new MemoryStream(LZ4.LZ4Codec.Decode(buffer, 4, buffer.Length - 4, outputLength), 0, outputLength, false, true); return(decompressStream); }
public Stream Decompress(Stream stream) { var buffer = Snappy.SnappyCodec.Uncompress(Utils.ReadAllBytes(stream, 0)); return(new MemoryStream(buffer, 0, buffer.Length, false, true)); }