Skip to content

Commit 9316a26

Browse files
committed
Add revert method
1 parent 19ed8a1 commit 9316a26

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/FontLib/BinaryStream.php

+15
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,20 @@ 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) {
90+
fclose($this->f);
91+
$this->f = $this->f2;
92+
$this->f2 = null;
93+
}
94+
}
95+
8196
/**
8297
* Change the internal file pointer
8398
*

0 commit comments

Comments
 (0)