Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
ec223d38
Commit
ec223d38
authored
Feb 08, 2018
by
Katherine Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-252: Allow seeking to advance chunk iterator instead of always re-querying
parent
0d3496dd
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
1 deletion
+46
-1
ReadableStream.php
src/GridFS/ReadableStream.php
+18
-1
ReadableStreamFunctionalTest.php
tests/GridFS/ReadableStreamFunctionalTest.php
+28
-0
No files found.
src/GridFS/ReadableStream.php
View file @
ec223d38
...
...
@@ -186,9 +186,26 @@ class ReadableStream
$this
->
chunkOffset
=
(
integer
)
floor
(
$offset
/
$this
->
chunkSize
);
$this
->
bufferOffset
=
$offset
%
$this
->
chunkSize
;
if
(
$lastChunkOffset
!==
$this
->
chunkOffset
)
{
/* If we are seeking to a previous chunk, we need to reinitialize the
* chunk iterator.
*/
if
(
$lastChunkOffset
>
$this
->
chunkOffset
)
{
$this
->
buffer
=
null
;
$this
->
chunksIterator
=
null
;
return
;
}
/* If we are seeking to a subsequent chunk, we do not need to
* reinitalize the chunk iterator. Instead, we can simply move forward
* to $this->chunkOffset.
*/
$numChunks
=
$this
->
chunkOffset
-
$lastChunkOffset
;
$i
=
0
;
if
(
$this
->
chunksIterator
!==
null
)
{
while
(
$i
<
$numChunks
)
{
$this
->
chunksIterator
->
next
();
$i
++
;
}
}
}
...
...
tests/GridFS/ReadableStreamFunctionalTest.php
View file @
ec223d38
...
...
@@ -199,4 +199,32 @@ class ReadableStreamFunctionalTest extends FunctionalTestCase
$stream
->
seek
(
11
);
}
public
function
testSeekPreviousChunk
()
{
$fileDocument
=
$this
->
collectionWrapper
->
findFileById
(
'length-10'
);
$stream
=
new
ReadableStream
(
$this
->
collectionWrapper
,
$fileDocument
);
$stream
->
readBytes
(
1
);
$stream
->
seek
(
5
);
$stream
->
seek
(
2
);
$stream
->
readBytes
(
1
);
}
public
function
testSeekSubsequentChunk
()
{
$fileDocument
=
$this
->
collectionWrapper
->
findFileById
(
'length-10'
);
$observer
=
$this
->
getMockBuilder
(
ReadableStream
::
class
)
->
setConstructorArgs
(
array
(
$this
->
collectionWrapper
,
$fileDocument
))
->
getMock
();
$observer
->
expects
(
$this
->
never
())
->
method
(
'initChunksIterator'
);
$observer
->
readBytes
(
1
);
$observer
->
seek
(
5
);
$observer
->
seek
(
2
);
$observer
->
readBytes
(
1
);
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment