Text
[ class tree: Text ] [ index: Text ] [ all elements ]

Class: Text_Huffman

Source Location: /Text_Huffman-0.2.0/Huffman.php

Class Overview


This class is intented to perform Huffman static compression on files with a PHP script.


Variables

Methods


Child classes:

Text_HuffmanCompress
Huffman Compression Class
Text_HuffmanExpand
Huffman Expansion Class

Inherited Variables

Inherited Methods


Class Details

[line 127]
This class is intented to perform Huffman static compression on files with a PHP script.

Such compression is essentially useful for reducing the size of texts by about 43% ; it is at its best when working with data containing strong redundancies at the character level -- that is, the opposite of a binary file in which the characters would be spread over the whole ASCII alphabet.

It is questionable whether anyone would want to do such an operation with PHP, when C implementations of much stronger and more versatile algorithms are readily avaible as PHP functions. The main drawback of this script class is slowness despite processing intensiveness (7 to 8 seconds to compress a 300Kb text, about 25 seconds to expand it back).

USE AND FUNCTION REFERENCE :

The 4 PHP files having been placed in the same directory, the only ones you have to include are compress.inc.php and/or expand.inc.php according to your needs.

----------------- -- Compression -- -----------------

Once a CPRS_Compress object has been constructed, the following functions are available :

  • setFiles('path/to/source/file', 'path/to/destination/file'):
This step is mandatory, as you give the paths to the file you want to compress, and the file you want the compressed output written to. These paths will be passed to the PHP fopen() function, see its reference for details. Note that the paths, if local, should be relative to the location of _your_ script, i.e. the one that has included this compression class.

  • setTimeLimit(int seconds):
This step is optional. It allows you to force a certain timeout limit for the PHP script, presumably longer than the default configuration on your server, should the job take too long. It simply calls the PHP set_time_limit() function.

  • compress():
This is the function that actually executes the job. It receives no parameters, and is of course obligatory.

--------------- -- Expansion -- ---------------

Once a CPRS_Expand object has been constructed, the following functions are available :

  • setFiles('path/to/source/file', 'path/to/destination/file'):
This step is mandatory, as you give the paths to the file containing the compressed data, and the file you want the expanded output written to. These paths will be passed to the PHP fopen() function, see its reference for details. Note that the paths, if local, should be relative to the location of _your_ script, i.e. the one that has included this compression class.

  • setTimeLimit(int seconds):
This step is optional. It allows you to force a certain timeout limit for the PHP script, presumably longer than the default configuration on your server, should the job take too long. It simply calls the PHP set_time_limit() function.

  • expand():
This is the function that actually executes the job. It receives no parameters, and is of course obligatory.

EXTRA NOTICE:

Please also note that some technical considerations apart from the core Huffman static algorithm have probably not been implemented after any standard in this class. That means that any other compressed file, even if you have reason to be certain that it was produced using the Huffman static algorithm, would in all probability not be usable as source file for data expansion with this class. In short, this class can very probably only restore what it itself compressed.

Anyway, thanks for using ! No feedback would be ignored. Feel free to tell me how you came in contact with this class, why you're using it (if at liberty to do so), and to suggest any enhancements, or of course to point out any serious bugs.



[ Top ]


Class Variables

$_havefiles =

[line 158]

Boolean to check files have been passed
  • Access: protected

Type:   mixed


[ Top ]

$_icarlen =

[line 140]

Length of the input carrier at any given time
  • Access: protected

Type:   mixed


[ Top ]

$_icarrier =

[line 134]

Carrier window for reading from input
  • Access: protected

Type:   mixed


[ Top ]

$_ifhand =

[line 182]

Resource handle of the input file
  • Access: protected

Type:   mixed


[ Top ]

$_ifile =

[line 176]

Path to the input file
  • Access: protected

Type:   mixed


[ Top ]

$_nodeChar =

[line 164]

Character representing a Branch Node in Tree transmission
  • Access: protected

Type:   mixed


[ Top ]

$_nodeCharC =

[line 170]

The same, character version as opposed to binary string
  • Access: protected

Type:   mixed


[ Top ]

$_nodes =

[line 206]

Array of Node objects
  • Access: protected

Type:   mixed


[ Top ]

$_ocarlen =

[line 152]

Length of the output carrier at any given time
  • Access: protected

Type:   mixed


[ Top ]

$_ocarrier =

[line 146]

Carrier window for writing to output
  • Access: protected

Type:   mixed


[ Top ]

$_odata =

[line 200]

Data eventually written to the output file
  • Access: protected

Type:   mixed


[ Top ]

$_ofhand =

[line 194]

Resource handle of the output file
  • Access: protected

Type:   mixed


[ Top ]

$_ofile =

[line 188]

Path to the output file
  • Access: protected

Type:   mixed


[ Top ]



Method Detail

__construct (Constructor)   [line 216]

Text_Huffman __construct( )

Constructor
  • Access: public

Overridden in child classes as:

Text_HuffmanCompress::__construct()
Constructor
Text_HuffmanExpand::__construct()
Constructor

[ Top ]

setFiles   [line 235]

void setFiles( [ $ifile = ''], [ $ofile = ''])

setFiles() is called to specify the paths to the input and output files.

Having set the relevant variables, it gets resource pointers to the files themselves.

  • Throws: Exception
  • Access: public

Overridden in child classes as:

Text_HuffmanCompress::setFiles()
setFiles() is called to specify the paths to the input and output files.

Parameters:

   $ifile   — 
   $ofile   — 

[ Top ]

_bitRead   [line 310]

void _bitRead( $len)

Bit-reading with a carrier: input 8 bits at a time.
  • Access: protected

Parameters:

   $len   — 

[ Top ]

_bitRead1   [line 343]

void _bitRead1( )

Read 1 bit.
  • Access: protected

[ Top ]

_bitWrite   [line 273]

void _bitWrite( $str, $len)

Bit-writing with a carrier: output every 8 bits
  • Access: protected

Parameters:

   $str   — 
   $len   — 

[ Top ]

_bitWriteEnd   [line 292]

void _bitWriteEnd( )

Finalizing bit-writing, writing the data.
  • Access: protected

[ Top ]

_decBinDig   [line 368]

void _decBinDig( $x, $n)

Returns the binary representation of $x as a string, over $n digits, with as many initial zeros as necessary to cover that.

Note: $n has to be more digits than the binary representation of $x originally has!

  • Access: protected

Parameters:

   $x   — 
   $n   — 

[ Top ]


Documentation generated on Mon, 11 Mar 2019 13:54:22 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.