Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.IO.Compression;
- using System.IO;
- using System.Diagnostics;
- namespace StreamZIP_A
- {
- class Program
- {
- static void Main(string[] args)
- {
- //deflate, gzip, Brotli, zip
- Stopwatch watch = Stopwatch.StartNew();
- //DEFLATE, compressione (4.7 sec)
- using (FileStream origine = File.OpenRead("enwik8.txt"))
- using (FileStream destinazione = File.Create("compressoDeflate.bin"))
- using (DeflateStream compressore = new(destinazione, CompressionMode.Compress))
- origine.CopyTo(compressore);
- watch.Stop();
- Console.WriteLine($"Deflate compressione {watch.ElapsedMilliseconds}");
- watch.Start();
- //DEFLATE, DEcompressione
- using (FileStream origine = File.OpenRead("compressoDeflate.bin"))
- using (FileStream destinazione = File.Create("DEcompressoDeflate.txt"))
- using (DeflateStream DeCompressore = new (origine, CompressionMode.Decompress))
- DeCompressore.CopyTo(destinazione);
- watch.Stop();
- Console.WriteLine($"Deflate DEcompressione {watch.ElapsedMilliseconds}");
- //Brotli, compressione
- watch.Start();
- using (FileStream origine = File.OpenRead("enwik8.txt"))
- using (FileStream destinazione = File.Create("compressoBrotli.bin"))
- using (BrotliStream compressore = new(destinazione, CompressionLevel.Fastest))
- origine.CopyTo(compressore);
- watch.Stop();
- Console.WriteLine($"Brotli compressione {watch.ElapsedMilliseconds}");
- watch.Start();
- //Brotli, DEcompressione
- using (FileStream origine = File.OpenRead("compressoBrotli.bin"))
- using (FileStream destinazione = File.Create("DEcompressoBrotli.txt"))
- using (BrotliStream DeCompressore = new(origine, CompressionMode.Decompress))
- DeCompressore.CopyTo(destinazione);
- watch.Stop();
- Console.WriteLine($"Brotlin DEcompressione {watch.ElapsedMilliseconds}");
- watch.Start();
- using (FileStream destinazione = File.Create("compressoZIP.zip"))
- using (ZipArchive zip = new(destinazione, ZipArchiveMode.Create))
- {
- zip.CreateEntryFromFile("enwik8.txt", "enwik8.txt");
- zip.CreateEntryFromFile("StreamZIP_A.dll", "StreamZIP_A.dll");
- zip.CreateEntryFromFile("compressoBrotli.bin", "compressoBrotli.bin");
- zip.CreateEntryFromFile("compressoDeflate.bin", "compressoDeflate.bin");
- }
- watch.Stop();
- Console.WriteLine($"ZIP compressione {watch.ElapsedMilliseconds}");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement