Exemple #1
0
        static void encode(string input, string fileName)
        {
            var haffman = new Tree();
            var bits    = haffman.Encode(input);
            var writer  = new BinStream(fileName + ".enc");

            writer.WriteBits(bits, FileMode.Create);
        }
Exemple #2
0
        static void decode(string fileName)
        {
            var haffman = new Tree();

            using (var file = new FileStream(fileName, FileMode.Open))
            {
                using (var binReader = new BinaryReader(file))
                {
                    var fileBits = new BinStream().ReadBits(binReader.ReadBytes((int)file.Length));
                    File.WriteAllText("DEC" + fileName.Remove(fileName.LastIndexOf(".")), haffman.Decode(fileBits),
                                      Encoding.GetEncoding(1251));
                }
            }
        }