PHP - Seek in filehandle pointing to file in zip? -
I want to print a particular line (200th standard) of a file in the zip archive. I am trying the following:
$ file = new SplFileObject ("zip: //archive.zip#file.txt"); $ File & gt; (200), echo $ file- & gt; Key () "\ N"; Echo $ file- & gt; Present ();
But I get
PHP Warning: SplFileObject :: seek (): does not support the demand in PHP.php on Stream Line 2 PHP Fatal Error: 'unreliable exception' can not rewind file with 'RuntimeException' message: //archive.zip # file.txt 'in script.php: 2
If I have to file With open and SplFileObject
parameter "file.txt"
, it works fine Does this document anywhere that zip file does not work for? I was unable to find it or am I doing something wrong? Thank you.
Good questions The behavior you want is clearly expressed by the syntax that you have used. is. I consider it a bug, you can probably report it here The stream should be controlled internally with no-rewind and cached.
Be careful! The solution of SplFileObject is more than wild.
NoRewind is required to reject rewinding. Then cache is required to store the stream content internally and make it searchable then it is necessary to look for the border line 200.
Here we go:
$ obj = new SplFileObject ("zip: //archive.zip#file.txt"); $ Naurwind = new no-reference operator ($ obz); $ Caching = new caching effector ($ Norway); $ Limit = new limit ($ caching, 200, 1); Forex currency ($ i => $ border as line $) {printf ("% 03d:% s", $ i, $ line); }
Comments
Post a Comment