File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace MongoDB \GridFS ;
4
4
5
- use MongoDB \Driver \ Exception \Exception ;
5
+ use MongoDB \Exception \InvalidArgumentException ;
6
6
use MongoDB \GridFS \Exception \CorruptFileException ;
7
7
use stdClass ;
8
8
@@ -68,10 +68,19 @@ public function close()
68
68
* if data is not available to be read.
69
69
*
70
70
* @param integer $numBytes Number of bytes to read
71
- * @return string
71
+ * @return string
72
+ * @throws InvalidArgumentException if $numBytes is negative
72
73
*/
73
74
public function downloadNumBytes ($ numBytes )
74
75
{
76
+ if ($ numBytes < 0 ) {
77
+ throw new InvalidArgumentException (sprintf ('$numBytes must be >= zero; given: %d ' , $ numBytes ));
78
+ }
79
+
80
+ if ($ numBytes == 0 ) {
81
+ return '' ;
82
+ }
83
+
75
84
if ($ this ->bufferFresh ) {
76
85
rewind ($ this ->buffer );
77
86
$ this ->bufferFresh = false ;
You can’t perform that action at this time.
0 commit comments