File tree Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Expand file tree Collapse file tree 1 file changed +18
-0
lines changed Original file line number Diff line number Diff 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 *
You can’t perform that action at this time.
0 commit comments