Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/ObjectStore/v1/Models/Container.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,10 +226,11 @@ public function createLargeObject(array $data): StorageObject
$service->createContainer(['name' => $segmentContainer]);
}

$promises = [];
$count = 0;
$promises = [];
$count = 0;
$totalSegments = $stream->getSize() / $segmentSize;

while (!$stream->eof() && $count < round($stream->getSize() / $segmentSize)) {
while (!$stream->eof() && $count < $totalSegments) {
$promises[] = $this->model(StorageObject::class)->createAsync([
'name' => sprintf('%s/%d', $segmentPrefix, ++$count),
'stream' => new LimitStream($stream, $segmentSize, ($count - 1) * $segmentSize),
Expand Down
3 changes: 2 additions & 1 deletion tests/unit/ObjectStore/v1/Models/ContainerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ public function test_other_exceptions_are_thrown()
public function test_it_chunks_according_to_provided_segment_size()
{
/** @var \GuzzleHttp\Psr7\Stream $stream */
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'Z')));
$stream = \GuzzleHttp\Psr7\stream_for(implode('', range('A', 'X')));

$data = [
'name' => 'object',
Expand All @@ -235,6 +235,7 @@ public function test_it_chunks_according_to_provided_segment_size()

$this->setupMock('PUT', 'segments', null, [], new Response(201));

// The stream has size 24 so we expect three segments.
$this->setupMock('PUT', 'segments/objectPrefix/1', $stream->read(10), [], new Response(201));
$this->setupMock('PUT', 'segments/objectPrefix/2', $stream->read(10), [], new Response(201));
$this->setupMock('PUT', 'segments/objectPrefix/3', $stream->read(10), [], new Response(201));
Expand Down