MediaWiki  master
SevenZipStream.php
Go to the documentation of this file.
1 <?php
28 
37  protected $stream;
38 
39  private function stripPath( $path ) {
40  $prefix = 'mediawiki.compress.7z://';
41 
42  return substr( $path, strlen( $prefix ) );
43  }
44 
45  public function stream_open( $path, $mode, $options, &$opened_path ) {
46  if ( $mode[0] == 'r' ) {
47  $options = 'e -bd -so';
48  } elseif ( $mode[0] == 'w' ) {
49  $options = 'a -bd -si';
50  } else {
51  return false;
52  }
53  $arg = Shell::escape( $this->stripPath( $path ) );
54  $command = "7za $options $arg";
55  if ( !wfIsWindows() ) {
56  // Suppress the stupid messages on stderr
57  $command .= ' 2>/dev/null';
58  }
59  // popen() doesn't like two-letter modes
60  $this->stream = popen( $command, $mode[0] );
61  return ( $this->stream !== false );
62  }
63 
64  public function url_stat( $path, $flags ) {
65  return stat( $this->stripPath( $path ) );
66  }
67 
68  public function stream_close() {
69  return fclose( $this->stream );
70  }
71 
72  public function stream_flush() {
73  return fflush( $this->stream );
74  }
75 
76  public function stream_read( $count ) {
77  return fread( $this->stream, $count );
78  }
79 
80  public function stream_write( $data ) {
81  return fwrite( $this->stream, $data );
82  }
83 
84  public function stream_tell() {
85  return ftell( $this->stream );
86  }
87 
88  public function stream_eof() {
89  return feof( $this->stream );
90  }
91 
92  public function stream_seek( $offset, $whence ) {
93  return fseek( $this->stream, $offset, $whence );
94  }
95 }
96 
97 stream_wrapper_register( 'mediawiki.compress.7z', SevenZipStream::class );
SevenZipStream\$stream
$stream
Definition: SevenZipStream.php:37
MediaWiki\Shell\Shell
Executes shell commands.
Definition: Shell.php:44
SevenZipStream\stream_write
stream_write( $data)
Definition: SevenZipStream.php:80
SevenZipStream\stream_read
stream_read( $count)
Definition: SevenZipStream.php:76
SevenZipStream\stream_seek
stream_seek( $offset, $whence)
Definition: SevenZipStream.php:92
SevenZipStream\stripPath
stripPath( $path)
Definition: SevenZipStream.php:39
SevenZipStream\stream_open
stream_open( $path, $mode, $options, &$opened_path)
Definition: SevenZipStream.php:45
SevenZipStream\url_stat
url_stat( $path, $flags)
Definition: SevenZipStream.php:64
SevenZipStream\stream_close
stream_close()
Definition: SevenZipStream.php:68
wfIsWindows
wfIsWindows()
Check if the operating system is Windows.
Definition: GlobalFunctions.php:1844
$command
$command
Definition: mcc.php:125
$path
$path
Definition: NoLocalSettings.php:25
SevenZipStream
Stream wrapper around 7za filter program.
Definition: SevenZipStream.php:36
SevenZipStream\stream_tell
stream_tell()
Definition: SevenZipStream.php:84
SevenZipStream\stream_flush
stream_flush()
Definition: SevenZipStream.php:72
SevenZipStream\stream_eof
stream_eof()
Definition: SevenZipStream.php:88