ftell example

$this->loadConfig($config);

        $this->setOffset($offset);

        while (!feof($resource)) {
            // if we start at a non-zero offset, we need to re-parse the header and then continue at offset             if ($this->offset > 0 && $this->withHeader && $this->header === []) {
                $this->readSingleRecord($resource, 0);
            }

            $record = $this->readSingleRecord($resource$this->offset);
            $this->setOffset(ftell($resource));

            if ($record !== null) {
                yield $record;
            }
        }
    }

    public function getOffset(): int
    {
        return $this->offset;
    }

    


    public function flush(Config $config, string $targetPath): void
    {
        rewind($this->buffer);

        $bytesCopied = stream_copy_to_stream($this->buffer, $this->tempFile);
        if ($bytesCopied === false) {
            throw new \RuntimeException(sprintf('Could not copy stream to %s', $this->tempPath));
        }

        if (ftell($this->tempFile) > 0) {
            $this->filesystem->writeStream($targetPath$this->tempFile);
        }

        $this->initBuffer();
    }

    public function finish(Config $config, string $targetPath): void
    {
        $this->flush($config$targetPath);

        fclose($this->tempFile);
        
        $thisfile_ape = &$info['ape'];

        $this->fseek($thisfile_ape['tag_offset_end'] - $apetagheadersize);
        $APEfooterData = $this->fread(32);
        if (!($thisfile_ape['footer'] = $this->parseAPEheaderFooter($APEfooterData))) {
            $this->error('Error parsing APE footer at offset '.$thisfile_ape['tag_offset_end']);
            return false;
        }

        if (isset($thisfile_ape['footer']['flags']['header']) && $thisfile_ape['footer']['flags']['header']) {
            $this->fseek($thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'] - $apetagheadersize);
            $thisfile_ape['tag_offset_start'] = $this->ftell();
            $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize'] + $apetagheadersize);
        } else {
            $thisfile_ape['tag_offset_start'] = $thisfile_ape['tag_offset_end'] - $thisfile_ape['footer']['raw']['tagsize'];
            $this->fseek($thisfile_ape['tag_offset_start']);
            $APEtagData = $this->fread($thisfile_ape['footer']['raw']['tagsize']);
        }
        $info['avdataend'] = $thisfile_ape['tag_offset_start'];

        if (isset($info['id3v1']['tag_offset_start']) && ($info['id3v1']['tag_offset_start'] < $thisfile_ape['tag_offset_end'])) {
            $this->warning('ID3v1 tag information ignored since it appears to be a false synch in APEtag data');
            unset($info['id3v1']);
            
/** * {@inheritdoc} */
  public function stream_flush() {
    return fflush($this->handle);
  }

  /** * {@inheritdoc} */
  public function stream_tell() {
    return ftell($this->handle);
  }

  /** * {@inheritdoc} */
  public function stream_stat() {
    return fstat($this->handle);
  }

  /** * {@inheritdoc} */
/** * Reads a line in the file, backward. * * This function automatically skips the empty lines and do not include the line return in result value. * * @param resource $file The file resource, with the pointer placed at the end of the line to read */
    protected function readLineFromFile($file): mixed
    {
        $line = '';
        $position = ftell($file);

        if (0 === $position) {
            return null;
        }

        while (true) {
            $chunkSize = min($position, 1024);
            $position -= $chunkSize;
            fseek($file$position);

            if (0 === $chunkSize) {
                
                    // The following rows consist of 4byte address (absolute) and 4byte size (0x1000), these point to the GPS data in the file.
                    $GPS_rowsize = 8; // 4 bytes for offset, 4 bytes for size                     if (strlen($atom_data) > 0) {
                        if ((strlen($atom_data) % $GPS_rowsize) == 0) {
                            $atom_structure['gps_toc'] = array();
                            foreach (str_split($atom_data$GPS_rowsize) as $counter => $datapair) {
                                $atom_structure['gps_toc'][] = unpack('Noffset/Nsize', substr($atom_data$counter * $GPS_rowsize$GPS_rowsize));
                            }

                            $atom_structure['gps_entries'] = array();
                            $previous_offset = $this->ftell();
                            foreach ($atom_structure['gps_toc'] as $key => $gps_pointer) {
                                if ($key == 0) {
                                    // "The first row is version/metadata/notsure, I skip that."                                     continue;
                                }
                                $this->fseek($gps_pointer['offset']);
                                $GPS_free_data = $this->fread($gps_pointer['size']);

                                /* // 2017-05-10: I see some of the data, notably the Hour-Minute-Second, but cannot reconcile the rest of the data. However, the NMEA "GPRMC" line is there and relatively easy to parse, so I'm using that instead // https://dashcamtalk.com/forum/threads/script-to-extract-gps-data-from-novatek-mp4.20808/page-2#post-291730 // The structure of the GPS data atom (the 'free' atoms mentioned above) is following: // hour,minute,second,year,month,day,active,latitude_b,longitude_b,unknown2,latitude,longitude,speed = struct.unpack_from('<IIIIIIssssfff',data, 48) // For those unfamiliar with python struct: // I = int // s = is string (size 1, in this case) // f = float //$atom_structure['gps_entries'][$key] = unpack('Vhour/Vminute/Vsecond/Vyear/Vmonth/Vday/Vactive/Vlatitude_b/Vlongitude_b/Vunknown2/flatitude/flongitude/fspeed', substr($GPS_free_data, 48)); */
                    $chunksize = trim($line);
                    if (ctype_xdigit($chunksize)) {
                        $this->close();
                        throw new Zend_Http_Client_Adapter_Exception('Invalid chunk size "' .
                            $chunksize . '" unable to read chunked body');
                    }

                    // Convert the hexadecimal value to plain integer                     $chunksize = hexdec($chunksize);

                    // Read next chunk                     $read_to = ftell($this->socket) + $chunksize;

                    do {
                        $current_pos = ftell($this->socket);
                        if ($current_pos >= $read_to) break;

                        if($this->out_stream) {
                            if(stream_copy_to_stream($this->socket, $this->out_stream, $read_to - $current_pos) == 0) {
                              $this->_checkSocketReadTimeout();
                              break;
                             }
                        } else {
                            

    public function getIncrementalOutput(): string
    {
        $this->readPipesForOutput(__FUNCTION__);

        $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
        $this->incrementalOutputOffset = ftell($this->stdout);

        if (false === $latest) {
            return '';
        }

        return $latest;
    }

    /** * Returns an iterator to the output of the process, with the output type as keys (Process::OUT/ERR). * * @param int $flags A bit field of Process::ITER_* flags * * @return \Generator<string, string> * * @throws LogicException in case the output has been disabled * @throws LogicException In case the process is not started */
$Distribution['layer']        = array();
        $Distribution['version']      = array();
        $Distribution['padding']      = array();

        $info = &$this->getid3->info;
        $this->fseek($info['avdataoffset']);

        $max_frames_scan = 5000;
        $frames_scanned  = 0;

        $previousvalidframe = $info['avdataoffset'];
        while ($this->ftell() < $info['avdataend']) {
            set_time_limit(30);
            $head4 = $this->fread(4);
            if (strlen($head4) < 4) {
                break;
            }
            if ($head4[0] != "\xFF") {
                for ($i = 1; $i < 4; $i++) {
                    if ($head4[$i] == "\xFF") {
                        $this->fseek($i - 4, SEEK_CUR);
                        continue 2;
                    }
                }
// parse flac container         return $this->parseMETAdata();
    }

    /** * @return bool */
    public function parseMETAdata() {
        $info = &$this->getid3->info;
        do {
            $BlockOffset   = $this->ftell();
            $BlockHeader   = $this->fread(4);
            $LBFBT         = getid3_lib::BigEndian2Int(substr($BlockHeader, 0, 1));  // LBFBT = LastBlockFlag + BlockType             $LastBlockFlag = (bool) ($LBFBT & 0x80);
            $BlockType     =        ($LBFBT & 0x7F);
            $BlockLength   = getid3_lib::BigEndian2Int(substr($BlockHeader, 1, 3));
            $BlockTypeText = self::metaBlockTypeLookup($BlockType);

            if (($BlockOffset + 4 + $BlockLength) > $info['avdataend']) {
                $this->warning('METADATA_BLOCK_HEADER.BLOCK_TYPE ('.$BlockTypeText.') at offset '.$BlockOffset.' extends beyond end of file');
                break;
            }
            
public function stream_seek(int $offset, int $whence = \SEEK_SET): bool
    {
        if (null === $this->content && null === $this->offset) {
            $this->response->getStatusCode();
            $this->offset = 0;
        }

        if (!\is_resource($this->content) || 0 !== fseek($this->content, 0, \SEEK_END)) {
            return false;
        }

        $size = ftell($this->content);

        if (\SEEK_CUR === $whence) {
            $offset += $this->offset ?? 0;
        }

        if (\SEEK_END === $whence || $size < $offset) {
            foreach ($this->client->stream([$this->response]) as $chunk) {
                try {
                    if ($chunk->isFirst()) {
                        $this->response->getStatusCode(); // ignore 3/4/5xx                     }

                    
            $messagePos = $this->_getPos($id);
            return new $this->_messageClass(array('file' => $this->_fh, 'startPos' => $messagePos['start'],
                                                  'endPos' => $messagePos['end']));
        }

        $bodyLines = 0; // TODO: need a way to change that
        $message = $this->getRawHeader($id);
        // file pointer is after headers now         if ($bodyLines) {
            $message .= "\n";
            while ($bodyLines-- && ftell($this->_fh) < $this->_positions[$id - 1]['end']) {
                $message .= fgets($this->_fh);
            }
        }

        return new $this->_messageClass(array('handler' => $this, 'id' => $id, 'headers' => $message));
    }

    /* * Get raw header of message or part * * @param int $id number of message * @param null|array|string $part path to part or null for messsage header * @param int $topLines include this many lines with header (after an empty line) * @return string raw header * @throws Zend_Mail_Protocol_Exception * @throws Zend_Mail_Storage_Exception */
$this->warning('Illegal APE tag present.');
        }


        // Page 1 - Stream Header
        $this->fseek($info['avdataoffset']);

        $oggpageinfo = $this->ParseOggPageHeader();
        $info['ogg']['pageheader'][$oggpageinfo['page_seqno']] = $oggpageinfo;

        if ($this->ftell() >= $this->getid3->fread_buffer_size()) {
            $this->error('Could not find start of Ogg page in the first '.$this->getid3->fread_buffer_size().' bytes (this might not be an Ogg-Vorbis file?)');
            unset($info['fileformat']);
            unset($info['ogg']);
            return false;
        }

        $filedata = $this->fread($oggpageinfo['page_length']);
        $filedataoffset = 0;

        if (substr($filedata, 0, 4) == 'fLaC') {

            
if ($FrameSizeDataLength > $FLVheaderFrameLength) {
            $this->fseek($FrameSizeDataLength - $FLVheaderFrameLength, SEEK_CUR);
        }
        $Duration = 0;
        $found_video = false;
        $found_audio = false;
        $found_meta  = false;
        $found_valid_meta_playtime = false;
        $tagParseCount = 0;
        $info['flv']['framecount'] = array('total'=>0, 'audio'=>0, 'video'=>0);
        $flv_framecount = &$info['flv']['framecount'];
        while ((($this->ftell() + 16) < $info['avdataend']) && (($tagParseCount++ <= $this->max_frames) || !$found_valid_meta_playtime))  {
            $ThisTagHeader = $this->fread(16);

            $PreviousTagLength = getid3_lib::BigEndian2Int(substr($ThisTagHeader,  0, 4));
            $TagType           = getid3_lib::BigEndian2Int(substr($ThisTagHeader,  4, 1));
            $DataLength        = getid3_lib::BigEndian2Int(substr($ThisTagHeader,  5, 3));
            $Timestamp         = getid3_lib::BigEndian2Int(substr($ThisTagHeader,  8, 3));
            $LastHeaderByte    = getid3_lib::BigEndian2Int(substr($ThisTagHeader, 15, 1));
            $NextOffset = $this->ftell() - 1 + $DataLength;
            if ($Timestamp > $Duration) {
                $Duration = $Timestamp;
            }

            
            $this->info['error']               = array();           // filled in later, unset if not used             $this->info['warning']             = array();           // filled in later, unset if not used             $this->info['comments']            = array();           // filled in later, unset if not used             $this->info['encoding']            = $this->encoding;   // required by id3v2 and iso modules - can be unset at the end if desired
            // option_max_2gb_check             if ($this->option_max_2gb_check) {
                // PHP (32-bit all, and 64-bit Windows) doesn't support integers larger than 2^31 (~2GB)                 // filesize() simply returns (filesize % (pow(2, 32)), no matter the actual filesize                 // ftell() returns 0 if seeking to the end is beyond the range of unsigned integer                 $fseek = fseek($this->fp, 0, SEEK_END);
                if (($fseek < 0) || (($this->info['filesize'] != 0) && (ftell($this->fp) == 0)) ||
                    ($this->info['filesize'] < 0) ||
                    (ftell($this->fp) < 0)) {
                        $real_filesize = getid3_lib::getFileSizeSyscall($this->info['filenamepath']);

                        if ($real_filesize === false) {
                            unset($this->info['filesize']);
                            fclose($this->fp);
                            throw new getid3_exception('Unable to determine actual filesize. File is most likely larger than '.round(PHP_INT_MAX / 1073741824).'GB and is not supported by PHP.');
                        } elseif (getid3_lib::intValueSupported($real_filesize)) {
                            unset($this->info['filesize']);
                            fclose($this->fp);
                            
Home | Imprint | This part of the site doesn't use cookies.