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