Esempio n. 1
0
 /**
  * Process the raw data from a binary stream
  * 
  * @param   Woops_Gzip_Binary_Stream    The binary stream
  * @return  void
  */
 public function processData(Woops_Gzip_Binary_Stream $stream)
 {
     // Gets the data length
     $length = $stream->littleEndianUnsignedShort();
     // Reads the field data
     $this->_data = $stream->read($length);
 }
Esempio n. 2
0
 /**
  * Class constructor
  * 
  * @param   resource    The file handle for which to create a binary stream
  * @param   boolean     Whether to close the file handle or not
  * @return  void
  * @see     Woops_Gzip_Binary_Stream::__construct
  */
 public function __construct($handle, $closeHandle = true)
 {
     // Checks if the file exists
     if (!is_resource($handle)) {
         // Error - The file does not exist
         throw new Woops_Gzip_Binary_File_Resource_Stream_Exception('Passed argument must be a valid file handle', Woops_Gzip_Binary_File_Resource_Stream_Exception::EXCEPTION_NO_RESOURCE);
     }
     // Storage
     $data = '';
     // Reads until the end of the file handle
     while (!feof($handle)) {
         // Reads from the file handle
         $data .= fread($handle, 8192);
     }
     // Checks if we must close the file handle
     if ($closeHandle) {
         // Closes the file handle
         fclose($handle);
     }
     // Calls the parent constructor
     parent::__construct($data);
 }
Esempio n. 3
0
 /**
  * Process the raw data from a binary stream
  * 
  * @param   Woops_Gzip_Binary_Stream    The binary stream
  * @return  void
  */
 public function processData(Woops_Gzip_Binary_Stream $stream)
 {
     // Gets the member signature
     $signature = $stream->littleEndianUnsignedShort();
     // Checks the member signature
     if ($signature !== 0x8b1f) {
         // Error - Invalid member signature
         throw new Woops_Gzip_Member_Exception('Invalid member signature (' . $signature . ')', Woops_Gzip_Member_Exception::EXCEPTION_BAD_SIGNATURE);
     }
     // Gets the compression method
     $this->_compressionMethod = $stream->unsignedChar();
     // Checks the compression method
     if ($this->_compressionMethod !== self::COMPRESSION_DEFLATE) {
         // Error - Invalid compression method
         throw new Woops_Gzip_Member_Exception('Invalid compression method (' . $this->_compressionMethod . ')', Woops_Gzip_Member_Exception::EXCEPTION_BAD_COMPRESSION_METHOD);
     }
     // Gets the flags
     $flags = $stream->unsignedChar();
     // Gets the modification time
     $this->_mTime = $stream->littleEndianUnsignedLong();
     // Gets the extra flags
     $extraFlags = $stream->unsignedChar();
     // Gets the operating system
     $this->_os = $stream->unsignedChar();
     // Checks for an extra field
     if ($flags & self::FLAG_EXTRA) {
         // Gets the extra field type
         $type = $stream->littleEndianUnsignedShort();
         // Checks if the type is known
         if (isset(self::$_extraFields[$type])) {
             // Gets the field class
             $fieldClass = self::$_extraFields[$type];
             // Creates the extra field
             $this->_extraField = new $fieldClass();
         } else {
             // Unknown extra field
             $this->_extraField = new Woops_Gzip_UnknownExtraField($type);
         }
         // Process the extra field data
         $this->_extraField->processData($stream);
     }
     // Checks for a file name
     if ($flags & self::FLAG_NAME) {
         // Gets the file name
         $this->_fileName = $stream->nullTerminatedString();
     }
     // Checks for a file comment
     if ($flags & self::FLAG_COMMENT) {
         // Gets the file comment
         $this->_fileComment = $stream->nullTerminatedString();
     }
     // Checks for a CRC16
     if ($flags & self::FLAG_HRCR) {
         // Gets the CRC16
         $crc16 = $stream->littleEndianUnsignedShort();
     }
 }