<?php class RawPage implements Page { private $git; private $hash; public function __construct( $git, $hash ) { $this->git = $git; $this->hash = $hash; } public function render() { $filename = $_GET['name'] ?? 'file'; $buffer = ''; $size = $this->git->getObjectSize( $this->hash ); $this->git->stream( $this->hash, function( $d ) use ( &$buffer ) { if( strlen( $buffer ) < 12 ) { $buffer .= $d; } } ); $mediaType = MediaTypeSniffer::isMediaType( $buffer, $filename ); while( ob_get_level() ) { ob_end_clean(); } 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; } }