Dave Jarvis' Repositories

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

Provides handle when reading

Author Dave Jarvis <email>
Date 2026-02-21 12:48:38 GMT-0800
Commit 20c681c974e61bf9503c7a12a50e06bdf48d0aae
Parent 4c9d86e
Delta 43 lines added, 32 lines removed, 11-line increase
git/PackEntryReader.php
$offset,
$cap,
- $pool,
- $packFile,
$readShaBaseFn
): string {
- fseek( $handle, $offset );
+ return $this->readWithHandle(
+ $handle,
+ $offset,
+ $cap,
+ $readShaBaseFn
+ );
+ },
+ ''
+ );
+ }
- $header = $this->readVarInt( $handle );
- $type = $header['byte'] >> 4 & 7;
- $result = '';
+ private function readWithHandle(
+ mixed $handle,
+ int $offset,
+ int $cap,
+ callable $readShaBaseFn
+ ): string {
+ fseek( $handle, $offset );
- if( $type === 6 ) {
- $neg = $this->readOffsetDelta( $handle );
- $cur = ftell( $handle );
- $base = $offset - $neg;
- $bData = $this->read(
- $pool,
- $packFile,
- $base,
- $cap,
- $readShaBaseFn
- );
+ $header = $this->readVarInt( $handle );
+ $type = $header['byte'] >> 4 & 7;
+ $result = '';
- fseek( $handle, $cur );
+ if( $type === 6 ) {
+ $neg = $this->readOffsetDelta( $handle );
+ $cur = ftell( $handle );
+ $base = $offset - $neg;
+ $bData = $this->readWithHandle(
+ $handle,
+ $base,
+ $cap,
+ $readShaBaseFn
+ );
- $delta = $this->inflate( $handle );
- $result = $this->decoder->apply( $bData, $delta, $cap );
- } elseif( $type === 7 ) {
- $sha = bin2hex( fread( $handle, 20 ) );
- $bas = $readShaBaseFn( $sha, $cap );
- $del = $this->inflate( $handle );
- $result = $this->decoder->apply( $bas, $del, $cap );
- } else {
- $result = $this->inflate( $handle, $cap );
- }
+ fseek( $handle, $cur );
- return $result;
- },
- ''
- );
+ $delta = $this->inflate( $handle );
+ $result = $this->decoder->apply( $bData, $delta, $cap );
+ } elseif( $type === 7 ) {
+ $sha = bin2hex( fread( $handle, 20 ) );
+ $bas = $readShaBaseFn( $sha, $cap );
+ $del = $this->inflate( $handle );
+ $result = $this->decoder->apply( $bas, $del, $cap );
+ } else {
+ $result = $this->inflate( $handle, $cap );
+ }
+
+ return $result;
}