/**
  * Extracts the contents from a GZIP file.
  * @param string $filename GZIP file name.
  * @param string $target   Target path.
  *
  * @throws Exception\IO\Input\FileCorruptedException
  *
  * @return bool
  */
 protected function extractGzipFile($filename, $target)
 {
     $fileHandler = fopen($filename, 'rb');
     $bitReader = new BitReader($fileHandler);
     // read file header
     try {
         $fileHeader = FileHeader::createFromResource($filename, $fileHandler);
     } catch (Exception\IO\Input\FileCorruptedException $e) {
         throw $e;
     }
     // read compressed blocks
     $result = '';
     $isBlockFinal = false;
     while (false === $isBlockFinal) {
         $isBlockFinal = 1 === $bitReader->read(1);
         $compressionType = $bitReader->read(2);
         if (self::COMPRESSION_TYPE_NON_COMPRESSED === $compressionType) {
             // no compression
             $data = unpack("vlength/vlengthOneComplement", fread($fileHandler, 4));
             $result .= fread($fileHandler, $data['length']);
         } else {
             // compression
             if (self::COMPRESSION_TYPE_FIXED_HUFFMAN === $compressionType) {
                 list($literalsTree, $distancesTree) = $this->getFixedHuffmanTrees();
             } elseif (self::COMPRESSION_TYPE_DYNAMIC_HUFFMAN === $compressionType) {
                 list($literalsTree, $distancesTree) = $this->getDynamicHuffmanTrees($bitReader);
             } else {
                 throw new Exception\IO\Input\FileCorruptedException($filename);
             }
             $result .= $this->uncompressCompressedBlock($literalsTree, $distancesTree, $bitReader, $result);
         }
         $literalsTree = null;
         $distancesTree = null;
     }
     // check crc32
     $footer = unpack('Vcrc/Visize', fread($fileHandler, 8));
     if ($footer['crc'] !== crc32($result)) {
         throw new Exception\IO\Input\FileCorruptedException($filename);
     }
     fclose($fileHandler);
     // write file
     $outputFilename = $fileHeader->getOriginalFilename();
     if (empty($outputFilename)) {
         $outputFilename = pathinfo($filename, PATHINFO_FILENAME);
     }
     $location = $target . DIRECTORY_SEPARATOR . $outputFilename;
     file_put_contents($location, $result);
     return true;
 }