cURL请求未使用CURLOPT_ENCODING标志


cURL request is not using the CURLOPT_ENCODING flag

我正试图下载一个直接gz'd到文件中的csv:

$fp = fopen ($file.'.csv', 'w+');
$ch = curl_init($url.'/'.$file.'.csv.gz');
curl_setopt($ch, CURLOPT_TIMEOUT, 50);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_ENCODING, 'gzip');
curl_exec($ch);
curl_close($ch);
fclose($fp);

最终发生的是{$file}.csv被写入磁盘,但它仍然被编码。如果我将存储的文件重命名为{$file}.csv.gz并对其进行gunzip,则数据将被正确解码。

我最终下载了这个文件,并创建了另一个代码块来解码它。

$buffer_size = 262144;
$in_file_handle = gzopen($symbol.'.csv.gz', 'rb');
$out_file_handle = fopen($symbol.'.csv', 'wb');
// Keep repeating until the end of the input file
while(!gzeof($in_file_handle)) {        
    fwrite($out_file_handle, gzread($in_file_handle, $buffer_size));
}
// Files are done, close files
fclose($out_file_handle);
gzclose($in_file_handle);

然而,我仍然非常有兴趣让curl一步到位。