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
6ab8c727
Commit
6ab8c727
authored
Jun 20, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Do not store entire files document in ReadableStream
parent
3cf99441
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
14 deletions
+35
-14
ReadableStream.php
src/GridFS/ReadableStream.php
+35
-14
No files found.
src/GridFS/ReadableStream.php
View file @
6ab8c727
...
...
@@ -17,11 +17,13 @@ class ReadableStream
private
$bufferEmpty
;
private
$bufferFresh
;
private
$bytesSeen
=
0
;
private
$chunkSize
;
private
$chunkOffset
=
0
;
private
$chunksIterator
;
private
$file
;
private
$firstCheck
=
true
;
private
$id
;
private
$iteratorEmpty
=
false
;
private
$length
;
private
$numChunks
;
/**
...
...
@@ -33,10 +35,24 @@ class ReadableStream
*/
public
function
__construct
(
CollectionWrapper
$collectionWrapper
,
stdClass
$file
)
{
$this
->
file
=
$file
;
if
(
!
isset
(
$file
->
chunkSize
)
||
!
is_integer
(
$file
->
chunkSize
)
||
$file
->
chunkSize
<
1
)
{
throw
new
CorruptFileException
(
'file.chunkSize is not an integer >= 1'
);
}
if
(
!
isset
(
$file
->
length
)
||
!
is_integer
(
$file
->
length
)
||
$file
->
length
<
0
)
{
throw
new
CorruptFileException
(
'file.length is not an integer > 0'
);
}
if
(
!
isset
(
$file
->
_id
)
&&
!
array_key_exists
(
'_id'
,
(
array
)
$file
))
{
throw
new
CorruptFileException
(
'file._id does not exist'
);
}
$this
->
id
=
$file
->
_id
;
$this
->
chunkSize
=
$file
->
chunkSize
;
$this
->
length
=
$file
->
length
;
$this
->
chunksIterator
=
$collectionWrapper
->
getChunksIteratorByFilesId
(
$this
->
file
->
_
id
);
$this
->
numChunks
=
(
$file
->
length
>=
0
)
?
ceil
(
$file
->
length
/
$file
->
chunkSize
)
:
0
;
$this
->
chunksIterator
=
$collectionWrapper
->
getChunksIteratorByFilesId
(
$this
->
id
);
$this
->
numChunks
=
ceil
(
$this
->
length
/
$this
->
chunkSize
)
;
$this
->
initEmptyBuffer
();
}
...
...
@@ -77,7 +93,7 @@ class ReadableStream
$output
.=
substr
(
$this
->
chunksIterator
->
current
()
->
data
->
getData
(),
0
,
$bytesLeft
);
}
if
(
!
$this
->
iteratorEmpty
&&
$this
->
file
->
length
>
0
&&
$bytesLeft
<
strlen
(
$this
->
chunksIterator
->
current
()
->
data
->
getData
()))
{
if
(
!
$this
->
iteratorEmpty
&&
$this
->
length
>
0
&&
$bytesLeft
<
strlen
(
$this
->
chunksIterator
->
current
()
->
data
->
getData
()))
{
fwrite
(
$this
->
buffer
,
substr
(
$this
->
chunksIterator
->
current
()
->
data
->
getData
(),
$bytesLeft
));
$this
->
bufferEmpty
=
false
;
}
...
...
@@ -103,19 +119,24 @@ class ReadableStream
}
}
public
function
getFile
()
{
return
$this
->
file
;
}
/**
* Return the ID of the GridFS file document for this stream.
*
* @return integer
*/
public
function
getId
()
{
return
$this
->
file
->
_
id
;
return
$this
->
id
;
}
/**
* Return the stream size in bytes.
*
* @return integer
*/
public
function
getSize
()
{
return
$this
->
file
->
length
;
return
$this
->
length
;
}
public
function
isEOF
()
...
...
@@ -149,8 +170,8 @@ class ReadableStream
$actualChunkSize
=
strlen
(
$this
->
chunksIterator
->
current
()
->
data
->
getData
());
$expectedChunkSize
=
(
$this
->
chunkOffset
==
$this
->
numChunks
-
1
)
?
(
$this
->
file
->
length
-
$this
->
bytesSeen
)
:
$this
->
file
->
chunkSize
;
?
(
$this
->
length
-
$this
->
bytesSeen
)
:
$this
->
chunkSize
;
if
(
$actualChunkSize
!=
$expectedChunkSize
)
{
throw
CorruptFileException
::
unexpectedSize
(
$actualChunkSize
,
$expectedChunkSize
);
...
...
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