コード例 #1
0
ファイル: Program.cs プロジェクト: Perf-Org-5KRepos/bion
        private static void Expand(string fromPath, string toPath, string fromDictionaryPath)
        {
            VerifyFileExists(fromPath);
            VerifyFileExists(fromDictionaryPath);

            using (new ConsoleWatch($"Expanding {fromPath}...",
                                    () => $"Done. {FileLength.MB(fromPath)} + {FileLength.MB(fromDictionaryPath)} dictionary to {FileLength.MB(toPath)}"))
            {
                WordCompressor.Expand(fromPath, toPath, fromDictionaryPath);
            }
        }
コード例 #2
0
        private void DecompressString()
        {
            if (_decompressReader == null)
            {
                _decompressReader = BufferedReader.FromArray(_reader.Buffer, 0, 0);
                _decompressWriter = BufferedWriter.ToArray(new byte[1024]);
            }

            _decompressReader.ReadSlice(_reader.Buffer, _currentCompressedStringStart, _reader.Index - 1);
            _decompressWriter.Index = 0;

            // Decompress the content
            _compressor.Expand(_decompressReader, _decompressWriter);

            // Make a String8 referencing the full decompressed value
            _currentString = String8.Reference(_decompressWriter.Buffer, 0, _decompressWriter.Index);
        }
コード例 #3
0
        public void WordCompressor_RoundTrip()
        {
            string originalPath   = @"Content\Medium.json";
            string compressedPath = "Medium.compressed.bin";
            string dictionaryPath = "Medium.compressed.dict";
            string comparePath    = "Medium.roundtrip.json";

            // Roundtrip without optimization; verify files equal
            WordCompressor.Compress(originalPath, compressedPath, dictionaryPath, false);
            WordCompressor.Expand(compressedPath, comparePath, dictionaryPath);
            Verify.FilesEqual(originalPath, comparePath);
            Verify.SizeRatioUnder(originalPath, compressedPath, 0.5f);

            File.Delete(compressedPath);
            File.Delete(dictionaryPath);
            File.Delete(comparePath);

            // Roundtrip *with* optimization; verify files equal
            WordCompressor.Compress(originalPath, compressedPath, dictionaryPath, true);
            WordCompressor.Expand(compressedPath, comparePath, dictionaryPath);
            Verify.FilesEqual(originalPath, comparePath);
            Verify.SizeRatioUnder(originalPath, compressedPath, 0.5f);
        }