Guzzle在从github下载归档文件时存储两份zip文件


Guzzle stores two copies of zip file when downloading archive from github

我有一个非常简单的guzzle请求到github下载zip档案:

$client = new 'Guzzle'Http'Client();
$response
  = $client->get("https://github.com/xxxxx/{$name}/zipball/master")
  ->setResponseBody($file)
  ->send();

问题是$file最终似乎包含两(2)个存档副本,即其大小恰好是运行获得的大小的两倍

wget https://github.com/xxxxx/{$name}/zipball/master

当然,unzip在解压狂饮版本时也会抱怨。在API的狂轰滥炸中,是否有我遗漏的东西,也许是由于重定向?

这是guzzle 3.9.2(2014-09-10),Linux,PHP 5.6.6(cli)(构建时间:2015年2月19日13:46:39)

我是Guzzle的新手,我可能错了,但。。。

似乎$client->get正在获取zip的副本,然后您将该副本作为响应主体发送回(从而将第一个副本添加到第二个副本的末尾),然后发送请求。

如果你只想下载一份zip,那么就这样做:

$client = new Client();
$response = $client->get('https://github.com/xxxxx/{$name}/zipball/master')->getBody();
file_put_contents("{$name}-master.zip", $response);