Skip to content

Commit

Permalink
Add revert method
Browse files Browse the repository at this point in the history
  • Loading branch information
lslqtz committed Feb 14, 2024
1 parent 19ed8a1 commit edcca2d
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/FontLib/BinaryStream.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class BinaryStream {
* @var resource The file pointer
*/
protected $f;
protected $f2;

const uint8 = 1;
const int8 = 2;
Expand Down Expand Up @@ -66,6 +67,9 @@ public function open($filename, $mode = self::modeRead) {
throw new \Exception("Unknown file open mode");
}

if ($this->f != null && $this->f != false) {
$this->f2 = $this->f;
}
$this->f = fopen($filename, $mode);

return $this->f != false;
Expand All @@ -75,9 +79,22 @@ public function open($filename, $mode = self::modeRead) {
* Close the internal file pointer
*/
public function close() {
if ($this->f2 !== null && $this->f2 !== false) {
fclose($this->f2);
}
return fclose($this->f) != false;
}

public function revert() {
if ($this->f2 !== null && $this->f !== null && $this->f !== false) {
fclose($this->f);
$this->f = $this->f2;
$this->f2 = null;
return true;
}
return false;
}

/**
* Change the internal file pointer
*
Expand Down

0 comments on commit edcca2d

Please sign in to comment.