Ejemplo n.º 1
0
 public EncodedFile encodeFile()
 {
     char[] charset = getCharset();
     int[] weights = getCharFrequencies(charset);
     HuffmanTree tree = new HuffmanTree(charset, weights);
     string[] codes = tree.getCodes(charset);
     string encoded = encodeToString(charset, codes);
     string huffmanData = tree.getBinaryRepresentation();
     Console.WriteLine(tree.getHuffmanCode(','));                //TEST TEST TEST
     EncodedFile enf = new EncodedFile("E:\\Users\\Alexander Weaver\\My Documents\\encodedTEST.hct", EncodedFile.CREATE_NEW);
     writeEncodedFile(enf, huffmanData, encoded);
     return enf;
 }
Ejemplo n.º 2
0
 //gets an encoded file from the user
 private EncodedFile getEncodedFile()
 {
     Console.WriteLine("Please enter the location of the encoded file you want to view.");
     string fp = Console.ReadLine();
     EncodedFile file;
     while (true) {
         try {
             file = new EncodedFile(fp, EncodedFile.USE_EXISTING);
         }
         catch (ArgumentException) {
             Console.WriteLine("Invalid filepath.");
             Console.WriteLine("Please enter a new filepath.");
             fp = Console.ReadLine();
             continue;
         }
         break;
     }
     return file;
     //return new EncodedFile("E:\\Users\\Alexander Weaver\\My Documents\\encodedTEST.hct", EncodedFile.USE_EXISTING);    //testing purposes
 }
Ejemplo n.º 3
0
 private void writeEncodedFile(EncodedFile enf, string huffmanData, string body)
 {
     BinaryWriter writer = new BinaryWriter(File.Open(enf.Filepath, FileMode.Create));
     writeBinaryString(huffmanData, writer, true);
     writeBinaryString(body, writer, false);
 }