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 8d1a6bc

Browse files
committedFeb 16, 2024
Add revert method
1 parent 19ed8a1 commit 8d1a6bc

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed
 

‎src/FontLib/BinaryStream.php

Lines changed: 18 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,12 @@ 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+
if ($this->f2 !== null && $this->f2 !== false) {
72+
fclose($this->f2);
73+
}
74+
$this->f2 = $this->f;
75+
}
6976
$this->f = fopen($filename, $mode);
7077

7178
return $this->f != false;
@@ -75,9 +82,20 @@ public function open($filename, $mode = self::modeRead) {
7582
* Close the internal file pointer
7683
*/
7784
public function close() {
85+
if ($this->f2 !== null && $this->f2 !== false) {
86+
fclose($this->f2);
87+
}
7888
return fclose($this->f) != false;
7989
}
8090

91+
public function revert() {
92+
if ($this->f2 !== null) {
93+
fclose($this->f);
94+
$this->f = $this->f2;
95+
$this->f2 = null;
96+
}
97+
}
98+
8199
/**
82100
* Change the internal file pointer
83101
*

0 commit comments

Comments
 (0)
Please sign in to comment.