Ejemplo n.º 1
0
        public static void Compress(string fromPath, string toPath, string toDictionaryPath, bool optimize = true)
        {
            using (WordCompressor compressor = WordCompressor.OpenWrite(toDictionaryPath))
            {
                string firstWritePath = toPath;
                if (optimize)
                {
                    firstWritePath = Path.ChangeExtension(toPath, ".tmp");
                }

                // First Pass
                using (BufferedReader reader = new BufferedReader(File.OpenRead(fromPath)))
                    using (BufferedWriter writer = new BufferedWriter(File.Create(firstWritePath)))
                    {
                        compressor.Compress(reader, writer);
                    }

                // Optimize Pass
                if (optimize)
                {
                    int[] map = compressor.OptimizeIndex();
                    using (BufferedReader reader = new BufferedReader(File.OpenRead(firstWritePath)))
                        using (BufferedWriter writer = new BufferedWriter(File.Create(toPath)))
                        {
                            compressor.RewriteOptimized(map, reader, writer);
                        }
                }
            }
        }
Ejemplo n.º 2
0
 public static void Expand(string fromPath, string toPath, string fromDictionaryPath)
 {
     using (WordCompressor compressor = WordCompressor.OpenRead(fromDictionaryPath))
         using (BufferedReader reader = new BufferedReader(File.OpenRead(fromPath)))
             using (BufferedWriter writer = new BufferedWriter(File.Create(toPath)))
             {
                 compressor.Expand(reader, writer);
             }
 }
Ejemplo n.º 3
0
        public static WordCompressor OpenRead(string dictionaryPath)
        {
            WordCompressor compressor = new WordCompressor();

            using (BionReader reader = new BionReader(File.OpenRead(dictionaryPath)))
            {
                compressor.Read(reader);
            }

            return(compressor);
        }