@@ -65,10 +65,11 @@ public function readme($username, $repository, $reference = null)
6565 * @param string $repository the name of the repository
6666 * @param string|null $path path to file or directory
6767 * @param string|null $reference reference to a branch or commit
68+ * @param array $requestHeaders request headers
6869 *
6970 * @return array|string information for file | information for each item in directory
7071 */
71- public function show ($ username , $ repository , $ path = null , $ reference = null )
72+ public function show ($ username , $ repository , $ path = null , $ reference = null , $ requestHeaders = [] )
7273 {
7374 $ url = '/repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/contents ' ;
7475 if (null !== $ path ) {
@@ -77,7 +78,7 @@ public function show($username, $repository, $path = null, $reference = null)
7778
7879 return $ this ->get ($ url , [
7980 'ref ' => $ reference ,
80- ]);
81+ ], $ requestHeaders );
8182 }
8283
8384 /**
@@ -272,9 +273,11 @@ public function archive($username, $repository, $format, $reference = null)
272273 *
273274 * @return string|null content of file, or null in case of base64_decode failure
274275 */
275- public function download ($ username , $ repository , $ path , $ reference = null )
276+ public function download ($ username , $ repository , $ path , $ reference = null , $ bodyType = null )
276277 {
277- $ file = $ this ->show ($ username , $ repository , $ path , $ reference );
278+ $ file = $ this ->show ($ username , $ repository , $ path , $ reference ,[
279+ 'Accept ' => 'application/vnd.github.VERSION.raw '
280+ ]);
278281
279282 if (!isset ($ file ['type ' ]) || !in_array ($ file ['type ' ], ['file ' , 'symlink ' ], true )) {
280283 throw new InvalidArgumentException (sprintf ('Path "%s" is not a file or a symlink to a file. ' , $ path ));
@@ -294,4 +297,24 @@ public function download($username, $repository, $path, $reference = null)
294297
295298 return base64_decode ($ file ['content ' ]) ?: null ;
296299 }
300+
301+ /**
302+ * Get the raw content of a file in a repository
303+ *
304+ * Use this method instead of the download method if your file is bigger than 1MB
305+ *
306+ * @see https://docs.github.com/en/rest/repos/contents
307+ *
308+ * @param string $username the user who owns the repository
309+ * @param string $repository the name of the repository
310+ * @param string $path path to file
311+ * @param string|null $reference reference to a branch or commit
312+ *
313+ * @return array|string
314+ */
315+ public function rawDownload ($ username , $ repository , $ path , $ reference = null ) {
316+ return $ this ->show ($ username , $ repository , $ path , $ reference , [
317+ 'Accept ' => 'application/vnd.github.VERSION.raw '
318+ ]);
319+ }
297320}
0 commit comments