// Called by the task when it is done with this writer, launches the async write internal void Flush() { OutputSize += _bufferPos; _writeTask = Task <uint> .Factory.StartNew(() => { if (Compress) { _compressor.Write(_memBuffer, 0, (int)_bufferPos); _compressor.Flush(); _compressor.Close(); _file.Flush(); } else { _file.Write(_memBuffer, 0, (int)_bufferPos); _file.Flush(); } var size = (uint)_file.Position; _compressor?.Dispose(); _file?.Dispose(); return(Compress ? size : 0); }); }
public static void Encode( string original, string encoded, int chuckSize, LZ4Settings settings) { var frameInfo = new LZ4Descriptor( null, false, settings.Chaining, false, null, settings.BlockSize); using (var input = File.OpenRead(original)) using (var output = File.Create(encoded)) using (var encode = new LZ4EncoderStream( output, frameInfo, i => LZ4Encoder.Create( i.Chaining, settings.Level, i.BlockSize, settings.ExtraBlocks))) { var buffer = new byte[chuckSize]; while (true) { var read = input.Read(buffer, 0, buffer.Length); if (read == 0) { break; } encode.Write(buffer, 0, read); } } }