static void CompressText(string text, string destinationFile, Lz4CompressionLevel level)
 {
   using (var writer = new FileStream(destinationFile, FileMode.Create))
   using (var lz4Stream = new LZ4Stream(writer, CompressionMode.Compress, Lz4CompressionLevel.Fastest))
   {
     var lineBytes = Encoding.ASCII.GetBytes(text);
     lz4Stream.Write(lineBytes, 0, lineBytes.Length);
   }
 }
 static void CompressFile(string sourceFile, string destinationFile, Lz4CompressionLevel level)
 {
   using (var writer = new FileStream(destinationFile, FileMode.Create))
   using (var sourceStream = new FileStream(sourceFile, FileMode.Open, FileAccess.Read, FileShare.Read))
   using (var reader = new StreamReader(sourceStream))
   using (var lz4Stream = new LZ4Stream(writer, CompressionMode.Compress, Lz4CompressionLevel.Fastest))
   {
     var allContent = reader.ReadToEnd();
     var allContentBytes = Encoding.ASCII.GetBytes(allContent);
     lz4Stream.Write(allContentBytes, 0, allContentBytes.Length);
   }
 }
 static void DecompressFile(string sourceFile, string destinationFile, int bufferSize = 100)
 {
   using (var writerStream = new FileStream(destinationFile, FileMode.Create))
   using (var writer = new StreamWriter(writerStream))
   using (var stream = new FileStream(sourceFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
   using (var lz4Stream = new LZ4Stream(stream, CompressionMode.Decompress))
   {
     foreach (var line in lz4Stream.ReadLines())
     {
       writer.WriteLine(line);
     }
   }
 }
 static void DecompressText(string sourceFile, string destinationFile, int bufferSize = 100)
 {
   using (var writerStream = new FileStream(destinationFile, FileMode.Create))
   using (var writer = new StreamWriter(writerStream))
   using (var stream = new FileStream(sourceFile, FileMode.OpenOrCreate, FileAccess.ReadWrite))
   using (var lz4Stream = new LZ4Stream(stream, CompressionMode.Decompress))
   using (var lz4Reader = new StreamReader(lz4Stream))
   {
     while (lz4Reader.Peek() > 0)
     {
       var line = lz4Reader.ReadLine();
       writer.WriteLine(line);
     }
   }
 }
 private static void CompressWithLZ4Stream(string uncompressedFile, string compressedFile, Func<int> bufferSizeGenerator, int bufferSize, Lz4CompressionLevel level)
 {
   using (var us = File.OpenRead(uncompressedFile))
   using (var cs = File.OpenWrite(compressedFile))
   using (var lz4s = new LZ4Stream(cs, CompressionMode.Compress, level))
   {
     us.CopyToWithBufferSizeGenerator(lz4s, bufferSizeGenerator, bufferSize);
   }
 }
 private void UncompressWithLZ4Stream(string compressedFile, string uncompressedFile, Func<int> bufferSizeGenerator, int bufferSize)
 {
   using (var cs = File.OpenRead(compressedFile))
   using (var us = File.OpenWrite(uncompressedFile))
   using (var lz4s = new LZ4Stream(cs, CompressionMode.Decompress))
   {
     lz4s.CopyToWithBufferSizeGenerator(us, bufferSizeGenerator, bufferSize);
   }
 }