/**
  * @param ReplayInterface $replay
  * @param int             $chunkId
  *
  * @return bool
  */
 private function downloadChunk(ReplayInterface $replay, $chunkId)
 {
     $chunk = $this->client->downloadChunk($replay->getRegion(), $replay->getGameId(), $chunkId);
     if (false === $chunk) {
         try {
             if ($chunkId > $this->findFirstChunkId($replay->getMetas()) && isset($replay->getMetas()['pendingAvailableChunkInfo'][0])) {
                 $replay->addDownloadRetry();
                 if ($this->options['replay.download.retry'] == $replay->getDownloadRetry()) {
                     return false;
                 } else {
                     sleep(1);
                     return $this->downloadChunk($replay, $chunkId);
                 }
             }
         } catch (\RuntimeException $e) {
             // No first chunk id was created, so it's the first download : we do nothing
         }
         // Clear retries
         $replay->resetDownloadRetry();
         return false;
     }
     $pathFolder = $this->getReplayDirPath($replay->getRegion(), $replay->getGameId()) . '/chunks';
     file_put_contents($pathFolder . '/' . $chunkId, $chunk);
     // Update metas
     $metas = $replay->getMetas();
     $metas['pendingAvailableChunkInfo'][] = array('duration' => 30000, 'id' => $chunkId, 'receivedTime' => date('M n, Y g:i:s A'));
     $replay->setMetas($metas);
     if ($this->options['replay.decoder.enable']) {
         $crypt = new ReplayCrypt($replay);
         if (!$this->onReplayFileDecrypted($replay, self::FILETYPE_CHUNK, $chunkId, $crypt->getBinary($replay, $pathFolder, $chunkId, $this->options['replay.decoder.save_files']))) {
             return false;
         }
     }
     return true;
 }