<?php/* * Reading a BZIP2 file can be tricky, and I never seen a complete example of * code that account for any possible failure that may happen accessing a file * in general, and decoding compressed data in this specific case. * The example that follows is my attempt to address this gap. * Some things that worth noting are: * - Encoding/decoding errors must be detected with bzerrno(). * - bzopen() may fail returning FALSE if the file cannot be created or read, * but succeeds also if the file is not properly encoded. * - bzread() may fail returning FALSE if it fails reading from the source, but * it returns the empty string on end of file and on encoding error. * - bzread() may still return corrupted data with no error whatsoever until the * BZIP2 algo encounters the first hash code, so data retrieved cannot be * trusted until the very end of the file has been reached. */