MediaWiki  REL1_19
7zip.inc
Go to the documentation of this file.
00001 <?php
00034 class SevenZipStream {
00035         var $stream;
00036 
00037         private function stripPath( $path ) {
00038                 $prefix = 'mediawiki.compress.7z://';
00039                 return substr( $path, strlen( $prefix ) );
00040         }
00041 
00042         function stream_open( $path, $mode, $options, &$opened_path ) {
00043                 if ( $mode[0] == 'r' ) {
00044                         $options = 'e -bd -so';
00045                 } elseif ( $mode[0] == 'w' ) {
00046                         $options = 'a -bd -si';
00047                 } else {
00048                         return false;
00049                 }
00050                 $arg = wfEscapeShellArg( $this->stripPath( $path ) );
00051                 $command = "7za $options $arg";
00052                 if ( !wfIsWindows() ) {
00053                         // Suppress the stupid messages on stderr
00054                         $command .= ' 2>/dev/null';
00055                 }
00056                 $this->stream = popen( $command, $mode[0] ); // popen() doesn't like two-letter modes
00057                 return ( $this->stream !== false );
00058         }
00059 
00060         function url_stat( $path, $flags ) {
00061                 return stat( $this->stripPath( $path ) );
00062         }
00063 
00064         // This is all so lame; there should be a default class we can extend
00065 
00066         function stream_close() {
00067                 return fclose( $this->stream );
00068         }
00069 
00070         function stream_flush() {
00071                 return fflush( $this->stream );
00072         }
00073 
00074         function stream_read( $count ) {
00075                 return fread( $this->stream, $count );
00076         }
00077 
00078         function stream_write( $data ) {
00079                 return fwrite( $this->stream, $data );
00080         }
00081 
00082         function stream_tell() {
00083                 return ftell( $this->stream );
00084         }
00085 
00086         function stream_eof() {
00087                 return feof( $this->stream );
00088         }
00089 
00090         function stream_seek( $offset, $whence ) {
00091                 return fseek( $this->stream, $offset, $whence );
00092         }
00093 }
00094 stream_wrapper_register( 'mediawiki.compress.7z', 'SevenZipStream' );