private double GetPpmdCompressionRatio <T>(string toUncompressedPath, IEnumerable <T> data) { //write uncompressed IFileWriter fWriter = new FileWriter(toUncompressedPath); fWriter.WriteText(data); //var data = BinaryConverter.ToBinArray(day.Data); //BinaryFileWriter.Write(toUncompressedPath, FileMode.CreateNew, data); //compress IArchiver archiver = new PPMDArchiver(); var toBeEncodedFileInfo = new FileInfo(toUncompressedPath); string encodedPath = archiver.Compress(toBeEncodedFileInfo); var fiUncompressed = new FileInfo(toUncompressedPath); var fiCompressed = new FileInfo(encodedPath); //compression rate double rate = (double)fiUncompressed.Length / fiCompressed.Length; //remove the files fiUncompressed.Delete(); fiCompressed.Delete(); return(rate); }
private IArchiver GetArchiver(CompressionType type) { IArchiver compressor; switch (type) { case CompressionType.Gzip: { compressor = new GZipArchiver(); break; } case CompressionType.Lzma: { compressor = new LZMAArchiver(); break; } case CompressionType.Ppmd: { compressor = new PPMDArchiver(); break; } default: throw new NotSupportedException(); } return(compressor); }
public void CompressDecompressWithPPMDTest() { string toBeEncodedPath = "file.txt"; string str = "012"; var sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.Append(str); } string expectedContent = sb.ToString(); File.WriteAllText(toBeEncodedPath, expectedContent, Encoding.ASCII); var toBeEncodedFileInfo = new FileInfo(toBeEncodedPath); IArchiver archiver = new PPMDArchiver(); string encodedPath = archiver.Compress(toBeEncodedFileInfo); var encodedFileInfo = new FileInfo(encodedPath); Assert.IsTrue(File.Exists(encodedPath)); Assert.IsTrue(encodedFileInfo.Length == 122); File.Delete(toBeEncodedPath); //DECODE string decodedPath = archiver.Decompress(encodedFileInfo); Assert.IsTrue(File.Exists(decodedPath)); string actualContent = File.ReadAllText(decodedPath); Assert.IsTrue(actualContent.Length == 300); Assert.AreEqual(expectedContent, expectedContent); }
public void PPMZArchiver_Compress() { string toBeEncodedPath = "file.txt"; string str = "012"; var sb = new StringBuilder(); for (int i = 0; i < 100; i++) { sb.Append(str); } string expectedContent = sb.ToString(); File.WriteAllText(toBeEncodedPath, expectedContent, Encoding.ASCII); var toBeEncodedFileInfo = new FileInfo(toBeEncodedPath); IArchiver archiver = new PPMDArchiver(); string encodedPath = archiver.Compress(toBeEncodedFileInfo); var encodedFileInfo = new FileInfo(encodedPath); Assert.IsTrue(File.Exists(encodedPath)); Assert.IsTrue(encodedFileInfo.Length == 122); }