1: <?php
2: 3: 4: 5: 6: 7: 8: 9:
10:
11: namespace OpenCloud\ObjectStore\Upload;
12:
13: use Guzzle\Http\EntityBody;
14: use Guzzle\Http\ReadLimitEntityBody;
15: use OpenCloud\Common\Constants\Size;
16:
17: 18: 19: 20: 21: 22:
23: class ConsecutiveTransfer extends AbstractTransfer
24: {
25:
26: public function transfer()
27: {
28: while (!$this->entityBody->isConsumed()) {
29:
30: if ($this->entityBody->getContentLength() && $this->entityBody->isSeekable()) {
31:
32: $body = new ReadLimitEntityBody($this->entityBody, $this->partSize, $this->entityBody->ftell());
33: } else {
34:
35: $body = EntityBody::factory();
36: $output = true;
37: while ($body->getContentLength() < $this->partSize && $output !== false) {
38:
39: $length = min(10 * Size::KB, $this->partSize - $body->getContentLength());
40: $output = $body->write($this->entityBody->read($length));
41: }
42: }
43:
44: if ($body->getContentLength() == 0) {
45: break;
46: }
47:
48: $request = TransferPart::createRequest(
49: $body,
50: $this->transferState->count() + 1,
51: $this->client,
52: $this->options
53: );
54:
55: $response = $request->send();
56:
57: $this->transferState->addPart(TransferPart::fromResponse($response));
58: }
59: }
60:
61: }