Advertisement
fcamuso

Streams - compressione con deflate

Aug 4th, 2021
1,083
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.18 KB | None | 0 0
  1. using System;
  2. using System.IO.Compression;
  3. using System.IO;
  4. using System.Diagnostics;
  5. using System.Threading;
  6.  
  7. namespace StreamZIP_A
  8. {
  9.   class Program
  10.   {
  11.     static void Main(string[] args)
  12.     {
  13.       //deflate, gzip, Brotli, zip
  14.  
  15.       Stopwatch watch = new Stopwatch();
  16.  
  17.       watch.Start();
  18.  
  19.       //DEFLATE, compressione (4.7 sec)
  20.       using (FileStream origine = File.OpenRead("enwik8.txt"))
  21.       using (FileStream destinazione = File.Create("compressoDeflate.bin"))
  22.       using (DeflateStream compressore = new DeflateStream(destinazione, CompressionMode.Compress))
  23.         origine.CopyTo(compressore);
  24.  
  25.       watch.Stop();
  26.       Console.WriteLine($"Deflate compressione {watch.ElapsedMilliseconds}");
  27.  
  28.       watch.Start();
  29.       //DEFLATE, DEcompressione
  30.       using (FileStream origine = File.OpenRead("compressoDeflate.bin"))
  31.       using (FileStream destinazione = File.Create("DEcompressoDeflate.txt"))
  32.       using (DeflateStream DeCompressore = new DeflateStream(origine, CompressionMode.Decompress))
  33.         DeCompressore.CopyTo(destinazione);
  34.       watch.Stop();
  35.       Console.WriteLine($"Deflate DEcompressione {watch.ElapsedMilliseconds}");
  36.  
  37.     }
  38.   }
  39. }
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement