public static void ReadFromCompressedStream(this Buffers toBuffer, Stream fromStream) { int numRead = 0; int chunckSize; do { MemoryStream memBytes = toBuffer.GetMemory(); //read length of block var position = fromStream.Position; chunckSize = (int)fromStream.ReadLong(); if (chunckSize > 0) { numRead = memBytes.ReadFromSetLen(fromStream, chunckSize); if (numRead > 0) { toBuffer.EnqueueBuffer(memBytes); } ThreadMessage($"{position} : {chunckSize}"); } }while (chunckSize > 0 && numRead > 0); }
public static void ReadFromStream(this Buffers toBuffer, Stream fromStream) { if (fromStream.Position == fromStream.Length) { return; } int count = toBuffer.BufferCapacity - sizeof(long); int numRead; do { var buffer = toBuffer.GetMemory(); #if DEBUGOUTPUT var position = fromStream.Position; #endif buffer.WriteLong(fromStream.Position); numRead = buffer.ReadFromSetLen(fromStream, count); if (numRead > 0) { toBuffer.EnqueueBuffer(buffer); } #if DEBUGOUTPUT ThreadMessage($"{position} : {numRead}"); #endif }while (numRead > 0 && numRead == count); }
public static void Decompress(this Buffers fromBuffer, Buffers toBuffer) { MemoryStream buffer; while ((buffer = fromBuffer.GetBuffer()) != null) { //decompress data var decompressed = buffer.DeCompress(toBuffer.GetMemory()); toBuffer.EnqueueBuffer(decompressed); fromBuffer.ReleaseBuffer(buffer); ThreadMessage($"{buffer.Length} : {decompressed.Length}"); } }
public static void Compress(this Buffers fromBuffer, Buffers toBuffers) { MemoryStream buffer; while ((buffer = fromBuffer.GetBuffer()) != null) { var compressed = buffer.Compress(toBuffers.GetMemory()); compressed.Position = 0; toBuffers.EnqueueBuffer(compressed); fromBuffer.ReleaseBuffer(buffer); //buffer.Position = 0; //var position = buffer.ReadLong(); ThreadMessage($"{buffer.Length} : {compressed.Length}"); } }