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  $this->stream = popen( $command, $mode[0] ); // popen() doesn't like two-letter modes
60  return ( $this->stream !== false );
61  }
62 
63  public function url_stat( $path, $flags ) {
64  return stat( $this->stripPath( $path ) );
65  }
66 
67  // This is all so lame; there should be a default class we can extend
68 
69  public function stream_close() {
70  return fclose( $this->stream );
71  }
72 
73  public function stream_flush() {
74  return fflush( $this->stream );
75  }
76 
77  public function stream_read( $count ) {
78  return fread( $this->stream, $count );
79  }
80 
81  public function stream_write( $data ) {
82  return fwrite( $this->stream, $data );
83  }
84 
85  public function stream_tell() {
86  return ftell( $this->stream );
87  }
88 
89  public function stream_eof() {
90  return feof( $this->stream );
91  }
92 
93  public function stream_seek( $offset, $whence ) {
94  return fseek( $this->stream, $offset, $whence );
95  }
96 }
97 
98 stream_wrapper_register( 'mediawiki.compress.7z', SevenZipStream::class );
wfIsWindows()
Check if the operating system is Windows.
stream_write( $data)
Stream wrapper around 7za filter program.
$command
Definition: mcc.php:125
url_stat( $path, $flags)
stream_read( $count)
stream_open( $path, $mode, $options, &$opened_path)
stream_seek( $offset, $whence)