lib/Github/Api/Repository/Contents.php
public function download($username, $repository, $path, $reference = null)
    {
        $file = $this->show($username, $repository, $path, $reference);

        if (!isset($file['type']) || !in_array($file['type'], ['file', 'symlink'], true)) {
            throw new InvalidArgumentException(sprintf('Path "%s" is not a file or a symlink to a file.', $path));
        }

        if (!isset($file['content'])) {
            throw new ErrorException(sprintf('Unable to access "content" for file "%s" (possible keys: "%s").', $path, implode(', ', array_keys($file))));
        }

        if (!isset($file['encoding'])) {
            throw new InvalidArgumentException(sprintf('Can\'t decode content of file "%s", as no encoding is defined.', $path));
        }

        if ('base64' !== $file['encoding']) {
            throw new InvalidArgumentException(sprintf('Encoding "%s" of file "%s" is not supported.', $file['encoding'], $path));
        }

        return base64_decode($file['content']) ?: null;
    }
public function download($username, $repository, $path, $reference = null)
    {
        $file = $this->show($username, $repository, $path, $reference);

        if (!isset($file['type']) || !in_array($file['type'], ['file', 'symlink'], true)) {
            throw new InvalidArgumentException(sprintf('Path "%s" is not a file or a symlink to a file.', $path));
        }

        if (!isset($file['content'])) {
            throw new ErrorException(sprintf('Unable to access "content" for file "%s" (possible keys: "%s").', $path, implode(', ', array_keys($file))));
        }

        if (!isset($file['encoding'])) {
            throw new InvalidArgumentException(sprintf('Can\'t decode content of file "%s", as no encoding is defined.', $path));
        }

        if ('base64' !== $file['encoding']) {
            throw new InvalidArgumentException(sprintf('Encoding "%s" of file "%s" is not supported.', $file['encoding'], $path));
        }

        return base64_decode($file['content']) ?: null;
    }
public function download ( $ username , $ repository , $ path , $ reference = null ) { $ file = $ this -> show ( $ username , $ repository , $ path , $ reference ) ; if ( ! isset ( $ file [ 'type' ] ) || ! in_array ( $ file [ 'type' ] , [ 'file' , 'symlink' ] , true ) ) { throw new InvalidArgumentException ( sprintf ( 'Path "%s" is not a file or a symlink to a file.' , $ path ) ) ; } if ( ! isset ( $ file [ 'content' ] ) ) { throw new ErrorException ( sprintf ( 'Unable to access "content" for file "%s" (possible keys: "%s").' , $ path , implode ( ', ' , array_keys ( $ file ) ) ) ) ; } if ( ! isset ( $ file [ 'encoding' ] ) ) { throw new InvalidArgumentException ( sprintf ( 'Can\'t decode content of file "%s", as no encoding is defined.' , $ path ) ) ; } if ( 'base64' !== $ file [ 'encoding' ] ) { throw new InvalidArgumentException ( sprintf ( 'Encoding "%s" of file "%s" is not supported.' , $ file [ 'encoding' ] , $ path ) ) ; } return base64_decode ( $ file [ 'content' ] ) ? : null ; }
Get the contents of a file in a repository.

@param string      $username   the user who owns the repository
@param string      $repository the name of the repository
@param string      $path       path to file
@param null|string $reference  reference to a branch or commit

@throws InvalidArgumentException If $path is not a file or if its encoding is different from base64
@throws ErrorException           If $path doesn't include a 'content' index

@return null|string content of file, or null in case of base64_decode failure
Get the contents of a file in a repository .