|
|
|
|
| Tutorial |
$file_handle = fopen($original_file, “r”);
if(!$file_handle)
die(“Error opening file.”);
// encode it
$output = encode_data();
// close input file
fclose($file_handle);
// open output file
$file_handle = fopen($compressed_file, “w”);
if(!$file_handle)
die(“Error creating file.”);
// write decoded data
for($i = 0; $i < count($output); $i++)
fputs($file_handle, $output[$i]);
// close output file
fclose($file_handle);
// open input file
$file_handle = fopen($compressed_file, “r”);
if(!$file_handle)
die(“Error opening file.”);
// decode it
$output = decode_data();
// close input file
fclose($file_handle);
// open output file
$file_handle = fopen($decompressed_file, “w”);
if(!$file_handle)
die(“Error creating file.”);
// write decoded data
for($i = 0; $i < count($output); $i++)
fputs($file_handle, $output[$i]);
// close file
fclose($file_handle);
This example shows very nicely how the decoder and reader logic can be split into
smaller, separate functions.The actual decoder is now only a few lines long.The
function that supplies input data can be detached from the rest of the code and the
“decision maker” that differentiates between literal and compressed data is again in a
separate, small, easy-to-understand function.
|
|
|
|
|
|
| Link Partners: Asia florist, Flowers to India, Hong kong flowers, Site submit, Cheap web hosting, China florist, Japan florist |
|