Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Checks stream resource, uses streaming interface

AuthorDave Jarvis <email>
Date2026-02-21 17:25:10 GMT-0800
Commit5abd9b113b5f2cf74713bec0770c7980b6d0c67f
Parentc3d1db9
git/DeltaDecoder.php
<?php
require_once __DIR__ . '/CompressionStream.php';
+require_once __DIR__ . '/StreamReader.php';
class DeltaDecoder {
public function applyStreamGenerator(
- mixed $handle,
+ StreamReader $handle,
mixed $base
): Generator {
$stream = CompressionStream::createInflater();
$state = 0;
$buffer = '';
$offset = 0;
$yieldBuffer = '';
- $isFile = is_resource( $base );
+ $isStream = $base instanceof StreamReader;
foreach( $stream->stream( $handle ) as $data ) {
);
- if( $isFile ) {
- fseek( $base, $info['off'] );
+ if( $isStream ) {
+ $base->seek( $info['off'] );
$rem = $info['len'];
while( $rem > 0 ) {
- $slc = fread( $base, min( self::CHUNK_SIZE, $rem ) );
+ $slc = $base->read( min( self::CHUNK_SIZE, $rem ) );
- if( $slc === false || $slc === '' ) {
+ if( $slc === '' ) {
$rem = 0;
} else {
}
- public function readDeltaTargetSize( mixed $handle, int $type ): int {
+ public function readDeltaTargetSize( StreamReader $handle, int $type ): int {
if( $type === 6 ) {
- $byte = ord( fread( $handle, 1 ) );
+ $byte = ord( $handle->read( 1 ) );
while( $byte & 128 ) {
- $byte = ord( fread( $handle, 1 ) );
+ $byte = ord( $handle->read( 1 ) );
}
} else {
- fseek( $handle, 20, SEEK_CUR );
+ $handle->seek( 20, SEEK_CUR );
}
}
- public function readDeltaBaseSize( mixed $handle ): int {
+ public function readDeltaBaseSize( StreamReader $handle ): int {
$stream = CompressionStream::createInflater();
$head = '';
Delta12 lines added, 11 lines removed, 1-line increase