seek example

EOD;

    $db->query($preSql);
    $dump->seek($offset);

    foreach (range(0, $batchSize - 1) as $count) {
        $sql = trim($dump->current());

        if (empty($sql)) {
            continue;
        }

        try {
            $db->query($sql);
        } catch (PDOException $e) {
            

        }

        $offset += $this->offset;

        if ($this->limit !== -1) {
            if ($offset > $this->offset + $this->limit) {
                $offset = $this->offset + $this->limit;
            }
        }

        $this->stream->seek($offset);
    }

    /** * Give a relative tell() */
    public function tell(): int
    {
        return $this->stream->tell() - $this->offset;
    }

    /** * Set the offset to start limiting from * * @param int $offset Offset to seek to and begin byte limiting from * * @throws \RuntimeException if the stream cannot be seeked. */

    public function run($offset)
    {
        $fs = new Filesystem();
        $requestTime = time();

        try {
            $source = new Zip($this->source);
            $count = $source->count();
            $source->seek($offset);
        } catch (Exception $e) {
            @unlink($this->source);
            throw new Exception(sprintf('Could not open update package:<br>%s', $e->getMessage()), 0, $e);
        }

        /** @var ZipEntry $entry */
        while (list($position$entry) = $source->each()) {
            $name = $entry->getName();
            $targetName = $this->destinationDir . $name;

            if (!$entry->isDir()) {
                
if ($pos > 0) {
            $stream->rewind();
        }

        $ctx = hash_init($algo);
        while (!$stream->eof()) {
            hash_update($ctx$stream->read(1048576));
        }

        $out = hash_final($ctx$rawOutput);
        $stream->seek($pos);

        return $out;
    }

    /** * Clone and modify a request with the given changes. * * This method is useful for reducing the number of clones needed to mutate * a message. * * The changes can be one of: * - method: (string) Changes the HTTP method. * - set_headers: (array) Sets the given headers. * - remove_headers: (array) Remove the given headers. * - body: (mixed) Sets the given body. * - uri: (UriInterface) Set the URI. * - query: (string) Set the query string value of the URI. * - version: (string) Set the protocol version. * * @param RequestInterface $request Request to clone and modify. * @param array $changes Changes to apply. */


        if (\is_string($content ?? '')) {
            $stream = $this->streamFactory->createStream($content ?? '');
        } elseif (\is_resource($content)) {
            $stream = $this->streamFactory->createStreamFromResource($content);
        } else {
            throw new \InvalidArgumentException(sprintf('"%s()" expects string, resource or StreamInterface, "%s" given.', __METHOD__, get_debug_type($content)));
        }

        if ($stream->isSeekable()) {
            $stream->seek(0);
        }

        return $stream;
    }

    public function createStreamFromFile(string $filename, string $mode = 'r'): StreamInterface
    {
        return $this->streamFactory->createStreamFromFile($filename$mode);
    }

    public function createStreamFromResource($resource): StreamInterface
    {
$dump = $this->dumper;

        $totalCount = $dump->count();

        $preSql = ' SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; SET @locale_de_DE = (SELECT id FROM s_core_locales WHERE locale = "de_DE"); SET @locale_en_GB = (SELECT id FROM s_core_locales WHERE locale = "en_GB"); ';
        $conn->exec($preSql);
        $dump->seek($offset);

        $startTime = microtime(true);
        $sql = [];
        $count = 0;
        while ($dump->valid() && ++$count) {
            $current = trim($dump->current());
            if (empty($current)) {
                $dump->next();
                continue;
            }

            
$data = $this->cloneVar($values);
        $clonedValues = [];

        $this->assertInstanceOf(Data::class$data);
        $this->assertCount(\count($values)$data);
        $this->assertFalse(isset($data->{0}));
        $this->assertFalse(isset($data[0]));

        foreach ($data as $k => $v) {
            $this->assertTrue(isset($data->{$k}));
            $this->assertTrue(isset($data[$k]));
            $this->assertSame(\gettype($values[$k])$data->seek($k)->getType());
            $this->assertSame($values[$k]$data->seek($k)->getValue());
            $this->assertSame($values[$k]$data->{$k});
            $this->assertSame($values[$k]$data[$k]);
            $this->assertSame((string) $values[$k](string) $data->seek($k));

            $clonedValues[$k] = $v->getValue();
        }

        $this->assertSame($values$clonedValues);
    }

    
 elseif (str_starts_with($childPath$chunk)) {
                    continue;
                }

                unset($children[$i]);
            }

            $it->next();
        }

        if (null !== $foundAtIndex) {
            $it->seek($foundAtIndex);
        }

        return $target;
    }

    /** * Reconstructs a property path from a violation path and a form tree. */
    private function reconstructPath(ViolationPath $violationPath, FormInterface $origin): ?RelativePath
    {
        $propertyPathBuilder = new PropertyPathBuilder($violationPath);
        


        if ($response instanceof StreamableInterface) {
            $body = $this->streamFactory->createStreamFromResource($response->toStream(false));
        } elseif (!$buffer) {
            $body = $this->streamFactory->createStreamFromResource(StreamWrapper::createResource($response$this->client));
        } else {
            $body = $this->streamFactory->createStream($response->getContent(false));
        }

        if ($body->isSeekable()) {
            $body->seek(0);
        }

        return $psrResponse->withBody($body);
    }
}
throw new \LogicException(sprintf('"%s" object holds non-iterable type "%s".', self::classget_debug_type($value)));
        }

        yield from $value;
    }

    /** * @return mixed */
    public function __get(string $key)
    {
        if (null !== $data = $this->seek($key)) {
            $item = $this->getStub($data->data[$data->position][$data->key]);

            return $item instanceof Stub || [] === $item ? $data : $item;
        }

        return null;
    }

    public function __isset(string $key): bool
    {
        return null !== $this->seek($key);
    }


    public function eof(): bool
    {
        return !$this->streams ||
            ($this->current >= count($this->streams) - 1 &&
             $this->streams[$this->current]->eof());
    }

    public function rewind(): void
    {
        $this->seek(0);
    }

    /** * Attempts to seek to the given position. Only supports SEEK_SET. */
    public function seek($offset$whence = SEEK_SET): void
    {
        if (!$this->seekable) {
            throw new \RuntimeException('This AppendStream is not seekable');
        } elseif ($whence !== SEEK_SET) {
            throw new \RuntimeException('The AppendStream can only seek with SEEK_SET');
        }
$flags = getenv('DUMP_LIGHT_ARRAY') ? CliDumper::DUMP_LIGHT_ARRAY : 0;
            $flags |= getenv('DUMP_STRING_LENGTH') ? CliDumper::DUMP_STRING_LENGTH : 0;
            $flags |= getenv('DUMP_COMMA_SEPARATOR') ? CliDumper::DUMP_COMMA_SEPARATOR : 0;
        }

        $cloner = new VarCloner();
        $cloner->addCasters($this->varDumperConfig['casters']);
        $cloner->setMaxItems(-1);
        $dumper = new CliDumper(null, null, $flags);
        $dumper->setColors(false);
        $data = $cloner->cloneVar($data$filter)->withRefHandles(false);
        if (null !== $key && null === $data = $data->seek($key)) {
            return null;
        }

        return rtrim($dumper->dump($data, true));
    }

    private function prepareExpectation(mixed $expected, int $filter): string
    {
        if (!\is_string($expected)) {
            $expected = $this->getDump($expected, null, $filter);
        }

        
$remoteSize = $this->remoteStream->getSize();

        if (null === $remoteSize) {
            return null;
        }

        return max($this->stream->getSize()$remoteSize);
    }

    public function rewind(): void
    {
        $this->seek(0);
    }

    public function seek($offset$whence = SEEK_SET): void
    {
        if ($whence === SEEK_SET) {
            $byte = $offset;
        } elseif ($whence === SEEK_CUR) {
            $byte = $offset + $this->tell();
        } elseif ($whence === SEEK_END) {
            $size = $this->remoteStream->getSize();
            if ($size === null) {
                

        return $this->stream->tell();
    }

    public function stream_eof(): bool
    {
        return $this->stream->eof();
    }

    public function stream_seek(int $offset, int $whence): bool
    {
        $this->stream->seek($offset$whence);

        return true;
    }

    /** * @return resource|false */
    public function stream_cast(int $cast_as)
    {
        $stream = clone $this->stream;
        $resource = $stream->detach();

        

    public function testSeekOnFtp()
    {
        $i = new RecursiveDirectoryIterator('ftp://speedtest:speedtest@ftp.otenet.gr/', \RecursiveDirectoryIterator::SKIP_DOTS);

        $contains = [
            'ftp://speedtest:speedtest@ftp.otenet.gr'.\DIRECTORY_SEPARATOR.'test100Mb.db',
            'ftp://speedtest:speedtest@ftp.otenet.gr'.\DIRECTORY_SEPARATOR.'test100k.db',
        ];
        $actual = [];

        $i->seek(0);
        $actual[] = $i->getPathname();

        $i->seek(1);
        $actual[] = $i->getPathname();

        $this->assertEquals($contains$actual);
    }
}
Home | Imprint | This part of the site doesn't use cookies.