| | private $hash; |
| | |
| | - public function __construct($git, $hash) { |
| | + public function __construct( $git, $hash ){ |
| | $this->git = $git; |
| | $this->hash = $hash; |
| | } |
| | |
| | - public function render() { |
| | + public function render(){ |
| | $filename = $_GET['name'] ?? 'file'; |
| | $buffer = ''; |
| | |
| | - // Get the exact size from git for the header |
| | - $size = $this->git->getObjectSize($this->hash); |
| | + $size = $this->git->getObjectSize( $this->hash ); |
| | |
| | - $this->git->stream($this->hash, function($d) use (&$buffer) { |
| | - if (strlen($buffer) < 12) $buffer .= $d; |
| | - }); |
| | + $this->git->stream( $this->hash, function( $d ) use ( &$buffer ){ |
| | + if( strlen( $buffer ) < 12 ){ |
| | + $buffer .= $d; |
| | + } |
| | + } ); |
| | |
| | - $mediaType = MediaTypeSniffer::isMediaType($buffer, $filename); |
| | + $mediaType = MediaTypeSniffer::isMediaType( $buffer, $filename ); |
| | |
| | - header("Content-Type: " . $mediaType); |
| | - header("Content-Length: " . $size); |
| | - header("Content-Disposition: inline; filename=\"" . addslashes($filename) . "\""); |
| | + if( ob_get_level() ){ |
| | + ob_end_clean(); |
| | + } |
| | |
| | - $this->git->stream($this->hash, function($d) { |
| | + header( "Content-Type: " . $mediaType ); |
| | + header( "Content-Length: " . $size ); |
| | + header( "Content-Disposition: inline; filename=\"" . addslashes( $filename ) . "\"" ); |
| | + |
| | + $this->git->stream( $this->hash, function( $d ){ |
| | echo $d; |
| | - }); |
| | + } ); |
| | + |
| | exit; |
| | } |