public function getChunksIteratorByFilesId($id) { $cursor = $this->chunksCollection->find(['files_id' => $id], ['sort' => ['n' => 1], 'typeMap' => ['root' => 'stdClass']]); return new IteratorIterator($cursor); }
/** * Constructs a readable GridFS stream. * * @param CollectionWrapper $collectionWrapper GridFS collection wrapper * @param stdClass $file GridFS file document * * @throws CorruptFileException */ public function __construct(CollectionWrapper $collectionWrapper, stdClass $file) { $this->file = $file; $this->chunksIterator = $collectionWrapper->getChunksIteratorByFilesId($this->file->_id); $this->numChunks = $file->length >= 0 ? ceil($file->length / $file->chunkSize) : 0; $this->initEmptyBuffer(); }