static void Huffman1(string[] args) { //try to open file by binary reader bool opened = OpenFile(args, out BinaryReader Reader, out BinaryWriter Writer); if (!opened) { return; } //create HuffmanReader, that is going to count occurences of bytes in input file HuffmanReader HuffReader = new HuffmanReader(Reader); bool NotEmpty = HuffReader.ReadFileUsingBuffer(); //Build Huffman tree TreeBuilder Builder = new TreeBuilder(HuffReader.ProvideSymbolsWihtWeights()); Node Root = Builder.BuildHuffTree(); Stream Outputstream = Console.OpenStandardOutput(); StreamWriter writer = new StreamWriter(Outputstream); //Writer.AutoFlush = true; Console.SetOut(writer); //print Huffman tree TreePrinter.PrintCompresedTree(Root, writer); }
/// <summary> /// Reads file, creates Huffman tree according its content and writes it to binary writer in specified binary representation /// </summary> /// <param name="reader"></param> /// <param name="writer"></param> /// <returns>Root of Huffman tree created</returns> internal static Node GenTree(BinaryReader reader, BinaryWriter writer) { HuffmanReader HuffReader = new HuffmanReader(reader); bool NotEmpty = HuffReader.ReadFileUsingBuffer(); //Build Huffman tree TreeBuilder Builder = new TreeBuilder(HuffReader.ProvideSymbolsWihtWeights()); Node Root = Builder.BuildHuffTree(); TreePrinter.PrintTreeBinary(Root, writer); writer.Flush(); return(Root); }