| | <?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 = ''; |