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