Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit edcca2d

Browse files
committedFeb 14, 2024
Add revert method
1 parent 19ed8a1 commit edcca2d

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed
 

‎src/FontLib/BinaryStream.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ class BinaryStream {
1818
* @var resource The file pointer
1919
*/
2020
protected $f;
21+
protected $f2;
2122

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

70+
if ($this->f != null && $this->f != false) {
71+
$this->f2 = $this->f;
72+
}
6973
$this->f = fopen($filename, $mode);
7074

7175
return $this->f != false;
@@ -75,9 +79,22 @@ public function open($filename, $mode = self::modeRead) {
7579
* Close the internal file pointer
7680
*/
7781
public function close() {
82+
if ($this->f2 !== null && $this->f2 !== false) {
83+
fclose($this->f2);
84+
}
7885
return fclose($this->f) != false;
7986
}
8087

88+
public function revert() {
89+
if ($this->f2 !== null && $this->f !== null && $this->f !== false) {
90+
fclose($this->f);
91+
$this->f = $this->f2;
92+
$this->f2 = null;
93+
return true;
94+
}
95+
return false;
96+
}
97+
8198
/**
8299
* Change the internal file pointer
83100
*

0 commit comments

Comments
 (0)
Please sign in to comment.