function BitRead1()
 {
     // Faster reading of just 1 bit
     // WARNING : requires icarrier to be originally empty !
     // NO keeping track of carrier length
     if ($this->icarrier == "") {
         $this->icarrier = DecBinDig(ord(fgetc($this->ifhand)), 8);
     }
     $ret = substr($this->icarrier, 0, 1);
     $this->icarrier = substr($this->icarrier, 1);
     return $ret;
 }
Beispiel #2
0
 function Compress()
 {
     if (!$this->havefiles) {
         $this->Error("Files not provided");
     }
     if ($this->debug_time) {
         $this->debug_t1 = time_micro();
     }
     //
     // WORKING WITH INPUT
     //
     // Counting letter occurrences in input file
     $this->CountOccurrences();
     // Converting occurrences into basic nodes
     // The nodes array has been initialized, as it will be filled with dynamic incrementation
     $this->Occs2Nodes();
     // Construction of the Huffman tree
     $this->MakeHuffmanTree();
     // Constructing character codes
     $this->MakeCharCodes();
     //
     // WORKING WITH OUTPUT
     //
     //!! No need for 8 bits of nb of chars in alphabet ?? still use $this -> nbchars ? NO
     //!! No need for 8+5+codelen bits of chars & codes ?? still use $this -> codelens array ? YES
     // Header : passing the Huffman tree with an automatically stopping algorithm
     $this->TransmitTree();
     // End of header : number of chars actually encoded, over 3 bytes
     $this->BitWrite(DecBinDig($this->ifsize, 24), 24);
     // Contents : compressed data
     rewind($this->ifhand);
     while (($char = fgetc($this->ifhand)) !== FALSE) {
         $this->BitWrite($this->codes[$char], $this->codelens[$char]);
     }
     // Finalising output, closing file handles
     $this->BitWrite_End();
     fclose($this->ofhand);
     fclose($this->ifhand);
     if ($this->debug_time) {
         $this->debug_t2 = time_micro();
     }
     // Calling Debug stuff in case any has been activated
     $this->ShowDebug();
 }