/** * @return bool * @throws \Exception */ protected function initFile() { if (parent::initFile()) { return true; } $this->fp = @fopen($this->filename, 'rb'); if ($this->fp === FALSE) { throw new \Exception("Invalid {$this->filename} file!"); } $offset = unpack('Nlen', fread($this->fp, 4)); $this->offset = $offset['len'] - 1024; if ($this->offset < 4) { throw new \Exception("Invalid {$this->filename} file!"); } $this->end = $this->offset - 4; $this->index = fread($this->fp, $this->end); $this->rewind(); return true; }
/** * @return bool * @throws \Exception */ protected function initFile() { if (parent::initFile()) { return true; } $this->fp = @fopen($this->filename, 'rb'); if ($this->fp === FALSE) { throw new \Exception("Invalid {$this->filename} file!"); } $offset = unpack('Vlen', fread($this->fp, 4)); $end = unpack('Vlen', fread($this->fp, 4)); $this->end = $end['len'] - $offset['len'] + 7; if ($offset['len'] < 4) { throw new \Exception("Invalid {$this->filename} file!"); } if ($this->end < 7) { throw new \Exception("Invalid {$this->filename} file!"); } fseek($this->fp, $offset['len']); $this->index = fread($this->fp, $this->end); return true; }