Skip to content

Commit 3a35083

Browse files
lewzylulewzylu
andauthored
fix getObject with saveas (#152)
Co-authored-by: lewzylu <lewzylu@tencent.com>
1 parent e3ddc10 commit 3a35083

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/Qcloud/Cos/ResultTransformer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,15 @@ public function writeDataToLocal(CommandInterface $command, RequestInterface $re
3333
if ($action == "GetObject") {
3434
if (isset($command['SaveAs'])) {
3535
$fp = fopen($command['SaveAs'], "wb");
36-
fwrite($fp, $response->getBody());
36+
$stream = $response->getBody();
37+
$offset = 0;
38+
$partsize = 8192;
39+
while (!$stream->eof()) {
40+
$output = $stream->read($partsize);
41+
fseek($fp, $offset);
42+
fwrite($fp, $output);
43+
$offset += $partsize;
44+
}
3745
fclose($fp);
3846
}
3947
}

0 commit comments

Comments
 (0)