INNER CODE UNIT · TypeScript

restoreGameState

ekzhang/setwithfriends · functions/src/index.ts:458

async function restoreGameState(gameId: string): Promise<boolean> {
  const file = getStorage().bucket().file(`gameData/${gameId}.json.gz`);
  let gzippedBlob: Buffer;
  try {
    [gzippedBlob] = await file.download();
  } catch (error: any) {
    // File was not present.
    if (error.code === 404) return false;
    throw error;
  }
  const jsonBlob = await gzip.decompress(gzippedBlob);

  const gameData = JSON.parse(jsonBlob.toString());
  await getDatabase()
    .ref(`gameData/${gameId}`)
    .set({ ...gameData, populatedAt: SERVER_VALUE_TIMESTAMP });
  return true;
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…