@@ -65,10 +65,11 @@ public function readme($username, $repository, $reference = null)
65
65
* @param string $repository the name of the repository
66
66
* @param string|null $path path to file or directory
67
67
* @param string|null $reference reference to a branch or commit
68
+ * @param array $requestHeaders request headers
68
69
*
69
70
* @return array|string information for file | information for each item in directory
70
71
*/
71
- public function show ($ username , $ repository , $ path = null , $ reference = null )
72
+ public function show ($ username , $ repository , $ path = null , $ reference = null , $ requestHeaders = [] )
72
73
{
73
74
$ url = '/repos/ ' .rawurlencode ($ username ).'/ ' .rawurlencode ($ repository ).'/contents ' ;
74
75
if (null !== $ path ) {
@@ -77,7 +78,7 @@ public function show($username, $repository, $path = null, $reference = null)
77
78
78
79
return $ this ->get ($ url , [
79
80
'ref ' => $ reference ,
80
- ]);
81
+ ], $ requestHeaders );
81
82
}
82
83
83
84
/**
@@ -272,9 +273,11 @@ public function archive($username, $repository, $format, $reference = null)
272
273
*
273
274
* @return string|null content of file, or null in case of base64_decode failure
274
275
*/
275
- public function download ($ username , $ repository , $ path , $ reference = null )
276
+ public function download ($ username , $ repository , $ path , $ reference = null , $ bodyType = null )
276
277
{
277
- $ file = $ this ->show ($ username , $ repository , $ path , $ reference );
278
+ $ file = $ this ->show ($ username , $ repository , $ path , $ reference ,[
279
+ 'Accept ' => 'application/vnd.github.VERSION.raw '
280
+ ]);
278
281
279
282
if (!isset ($ file ['type ' ]) || !in_array ($ file ['type ' ], ['file ' , 'symlink ' ], true )) {
280
283
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)
294
297
295
298
return base64_decode ($ file ['content ' ]) ?: null ;
296
299
}
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
+ }
297
320
}
0 commit comments