public void Write(IByteBlock byteBlock) { lock (_fileStreamLocker) { _Write(byteBlock); } }
private void WriteByteBlock(IByteBlock byteBlock) { if (!CanWrite) { throw new InvalidOperationException("The file couldn't be written."); } _fileStream.Write(byteBlock.Buffer, 0, byteBlock.BufferSize); }
private IByteBlock DecompressByteBlock(IByteBlock byteBlock) { using var memoryStream = new MemoryStream(byteBlock.Buffer); using var compressStream = new GZipStream(memoryStream, CompressionMode.Decompress); var resultByteBlock = new ByteBlock(byteBlock.Index, DataConfiguration.DefaultByteBlockSize); compressStream.Read(resultByteBlock.Buffer, 0, resultByteBlock.BufferSize); return(resultByteBlock); }
private IByteBlock CompressByteBlock(IByteBlock byteBlock) { using var memoryStream = new MemoryStream(); using var compressStream = new GZipStream(memoryStream, CompressionMode.Compress); compressStream.Write(byteBlock.Buffer, 0, byteBlock.BufferSize); return(new ByteBlock(byteBlock.Index, memoryStream.Length) { Buffer = memoryStream.ToArray() }); }
private void WriteByteBlockToArchive(IByteBlock byteBlock) { if (!CanWrite) { throw new InvalidOperationException("The file couldn't be written."); } _fileStream.Write(BitConverter.GetBytes(byteBlock.BufferSize), 0, sizeof(int)); _fileStream.Write(BitConverter.GetBytes(byteBlock.Index), 0, sizeof(int)); _fileStream.Write(byteBlock.Buffer, 0, byteBlock.BufferSize); }
public void Add(int index, IByteBlock byteBlock) { if (IsFull) { _addLocker.WaitOne(); } lock (_byteBlocksLocker) { if (_byteBlocks.ContainsKey(index)) { throw new IndexOutOfRangeException($"There is already a key in the pool: {index.ToString()}"); } _byteBlocks.Add(index, byteBlock); } if (!IsFull) { _addLocker.Set(); } }