我必須解析很多(10000+)遠程gzip文件。每個壓縮文件都應該包含一個CSV文件(可能位於一個文件夾中)。現在我可以獲取主體,檢查內容類型並解壓縮,獲取application/octet-stream
。如何在PHP中處理application/octet-stream(未壓縮的gzip文件)?
問題是:什麼是八位字節流,我如何檢查裏面的文件或文件夾?
/** @var $guzzle \Guzzle\Http\Client */
$guzzle = $this->getContainer()->get('guzzle');
$request = $guzzle->get($url);
try {
$body = $request->send()->getBody();
// Check for body content-type
if('application/z-gzip' === $body->getContentType()) {
$body->uncompress();
$body->getContentType(); // application/octet-stream
}
else {
// Log and skip current remote file
}
}
catch(\Exception $e) {
$output->writeln("Failed: {$guzzle->getBaseUrl()}");
throw $e;
}
沒有任何答案的協助之下這個老問題,@gremo? – halfer