00001 <?php
00009 class SevenZipStream {
00010 var $stream;
00011
00012 private function stripPath( $path ) {
00013 $prefix = 'mediawiki.compress.7z://';
00014 return substr( $path, strlen( $prefix ) );
00015 }
00016
00017 function stream_open( $path, $mode, $options, &$opened_path ) {
00018 if( $mode[0] == 'r' ) {
00019 $options = 'e -bd -so';
00020 } elseif( $mode[0] == 'w' ) {
00021 $options = 'a -bd -si';
00022 } else {
00023 return false;
00024 }
00025 $arg = wfEscapeShellArg( $this->stripPath( $path ) );
00026 $command = "7za $options $arg";
00027 if( !wfIsWindows() ) {
00028
00029 $command .= ' 2>/dev/null';
00030 }
00031 $this->stream = popen( $command, $mode );
00032 return ($this->stream !== false);
00033 }
00034
00035 function url_stat( $path, $flags ) {
00036 return stat( $this->stripPath( $path ) );
00037 }
00038
00039
00040
00041 function stream_close() {
00042 return fclose( $this->stream );
00043 }
00044
00045 function stream_flush() {
00046 return fflush( $this->stream );
00047 }
00048
00049 function stream_read( $count ) {
00050 return fread( $this->stream, $count );
00051 }
00052
00053 function stream_write( $data ) {
00054 return fwrite( $this->stream, $data );
00055 }
00056
00057 function stream_tell() {
00058 return ftell( $this->stream );
00059 }
00060
00061 function stream_eof() {
00062 return feof( $this->stream );
00063 }
00064
00065 function stream_seek( $offset, $whence ) {
00066 return fseek( $this->stream, $offset, $whence );
00067 }
00068 }
00069 stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );