public static void Huff(Stream sin, Stream sout, UpdateCRC callback)
        {
            Tree t = new Tree ();
            int rd, i, tmp;
            Stack<int> ret;
            BitIO bw = new BitIO (sout, true);
            while ((rd = sin.ReadByte ()) != -1) {
                tmp = rd;
                callback ((byte)tmp);
                if (!t.contains (rd)) {
                    ret = t.GetCode (257);
                    while (ret.Count > 0)
                        bw.WriteBit (ret.Pop ());
                    for (i = 0; i < 8; i++) {
                        bw.WriteBit ((int)(rd & 0x80));
                        rd <<= 1;
                    }
                    t.UpdateTree (tmp);
                }
                else {
                    ret = t.GetCode (tmp);
                    while (ret.Count > 0)
                        bw.WriteBit (ret.Pop ());
                    t.UpdateTree (tmp);
                }
            }

            ret = t.GetCode (256);
            while (ret.Count > 0) {
                bw.WriteBit (ret.Pop ());
            }
        }
 protected virtual void OnRedoActionActivated(object sender, System.EventArgs e)
 {
     if (tree_updating)
         return;
     SenderTree = new HuffLibrary.Tree ();
     ReceiverTree = new HuffLibrary.Tree ();
     SenderEntry.Text = DecEntry.Text = BinEntry.Text = "";
     UpdateReceiverTree ();
     UpdateSenderTree ();
 }
 public static void UnHuff(Stream InStream, Stream OutStream)
 {
     int i = 0, count = 0;
     Tree t = new Tree ();
     BitIO bitIO = new BitIO (InStream, false);
     while ((i = bitIO.ReadBit ()) != 2) {
         if ((count = t.DecodeBinary (i)) != Tree.CharIsEof)
             OutStream.WriteByte ((byte)count);
     }
 }
 public static void UnHuff(Stream InStream, Stream OutStream, UpdateCRC callback)
 {
     int i = 0, count = 0, sym;
     Tree t = new Tree ();
     BitIO bitIO = new BitIO (InStream, false);
     while ((i = bitIO.ReadBit ()) != 2) {
         if ((sym = t.DecodeBinary (i)) != Tree.CharIsEof) {
             OutStream.WriteByte ((byte)sym);
             callback (sym);
             count++;
         }
     }
 }