3 * Stream wrapper around 7za filter program.
4 * Required since we can't pass an open file resource to XMLReader->open()
5 * which is used for the text prefetch.
12 private function stripPath( $path ) {
13 $prefix = 'mediawiki.compress.7z://';
14 return substr( $path, strlen( $prefix ) );
17 function stream_open( $path, $mode, $options, &$opened_path ) {
18 if( $mode[0] == 'r' ) {
19 $options = 'e -bd -so';
20 } elseif( $mode[0] == 'w' ) {
21 $options = 'a -bd -si';
25 $arg = wfEscapeShellArg( $this->stripPath( $path ) );
26 $command = "7za $options $arg";
27 if( !wfIsWindows() ) {
28 // Suppress the stupid messages on stderr
29 $command .= ' 2>/dev/null';
31 $this->stream = popen( $command, $mode );
32 return ($this->stream !== false);
35 function url_stat( $path, $flags ) {
36 return stat( $this->stripPath( $path ) );
39 // This is all so lame; there should be a default class we can extend
41 function stream_close() {
42 return fclose( $this->stream );
45 function stream_flush() {
46 return fflush( $this->stream );
49 function stream_read( $count ) {
50 return fread( $this->stream, $count );
53 function stream_write( $data ) {
54 return fwrite( $this->stream, $data );
57 function stream_tell() {
58 return ftell( $this->stream );
61 function stream_eof() {
62 return feof( $this->stream );
65 function stream_seek( $offset, $whence ) {
66 return fseek( $this->stream, $offset, $whence );
69 stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );