tinyfiles.tv · Save Format & Architecture
tinysave.
Downloadable <game>.tinysave files, URL hash links, versioned checksum envelopes, offline timestamp deltas, and optional PHP/Python wiring—without needing a database first.
How .tinysave Moves
FIG. 1 — Client-first .tinysave flow: browser state works standalone via localStorage, #s= hash, and .tinysave files, with optional PHP/Python file endpoints.
Interactive .tinysave Playground
[2026-11-22 07:23:00] [game:ecosystem] (local) exported ecosystem.tinysave (v1)
The Four Client-Side Patterns in Code
1. URL Hash (#s=...) for Instant Sharing
function saveStateToHash(game, state) {
const encoded = btoa(unescape(encodeURIComponent(JSON.stringify({ v: 1, game, state }))));
history.replaceState(null, "", "#s=" + encoded);
return location.href;
}
function loadStateFromHash(expectedGame) {
if (!location.hash.startsWith("#s=")) return null;
try {
const json = decodeURIComponent(escape(atob(location.hash.slice(3))));
const doc = JSON.parse(json);
if (!doc || doc.v !== 1 || (expectedGame && doc.game !== expectedGame)) return null;
return doc.state;
} catch (err) {
return null;
}
}
2. Compact JSON + Version Tag & FNV-1a Checksum
function fnv1aHex(str) {
let hash = 0x811c9dc5;
for (let i = 0; i < str.length; i++) {
hash ^= str.charCodeAt(i);
hash = Math.imul(hash, 0x01000193);
}
return (hash >>> 0).toString(16).padStart(8, "0");
}
function makeEnvelope(game, code, state) {
const payloadStr = JSON.stringify({ game, code, state });
const sum = fnv1aHex(payloadStr);
return {
format: "tinysave",
version: 1,
game,
code,
savedAt: new Date().toISOString(),
sum,
state
};
}
function verifyEnvelope(doc) {
if (!doc || doc.format !== "tinysave" || doc.version !== 1 || !doc.state) return false;
const payloadStr = JSON.stringify({ game: doc.game, code: doc.code, state: doc.state });
return fnv1aHex(payloadStr) === doc.sum;
}
3. Downloadable <game>.tinysave File + localStorage
function exportTinysaveFile(game, code, state) {
const doc = makeEnvelope(game, code, state);
try {
localStorage.setItem("tinysave:" + game + ":v1", JSON.stringify(doc));
} catch (e) {}
const blob = new Blob([JSON.stringify(doc, null, 2)], { type: "application/json" });
const url = URL.createObjectURL(blob);
const link = document.createElement("a");
link.href = url;
link.download = `${game}.tinysave`;
document.body.appendChild(link);
link.click();
link.remove();
setTimeout(() => URL.revokeObjectURL(url), 1000);
return doc;
}
4. Timestamp Delta Math for "Living" State
function advanceLivingState(state, nowMs = Date.now(), maxElapsedSec = 86400) {
if (!state.lastTickAt) {
state.lastTickAt = nowMs;
return state;
}
const rawSec = Math.max(0, (nowMs - Number(state.lastTickAt)) / 1000);
const dtSec = Math.min(rawSec, maxElapsedSec); // prevents huge jumps from old saves
if (state.meters && typeof state.meters.oxygen === "number") {
state.meters.oxygen = Math.max(0, Math.min(100, state.meters.oxygen - dtSec * 0.01));
}
state.lastTickAt = nowMs;
return state;
}
Optional Backend Wiring (No DB Required)
When you eventually want optional server storage or inspection without standing up MySQL/SQLite, you can POST a .tinysave JSON document to a small PHP file writer, inspect/process it in Python, and append a single line to an event log.
PHP Endpoint · /api/tinysave.php (File-backed, No DB)
<?php
// File: /var/www/tinyfiles.tv/api/tinysave.php
header("Content-Type: application/json; charset=utf-8");
header("X-Content-Type-Options: nosniff");
if ($_SERVER["REQUEST_METHOD"] !== "POST") {
http_response_code(405);
echo json_encode(["ok" => false, "error" => "Method not allowed"]);
exit;
}
$raw = file_get_contents("php://input");
if (strlen($raw) > 65536) {
http_response_code(413);
echo json_encode(["ok" => false, "error" => "Payload too large (64KB max)"]);
exit;
}
$doc = json_decode($raw, true);
if (!is_array($doc) || ($doc["format"] ?? "") !== "tinysave" || !is_array($doc["state"] ?? null)) {
http_response_code(400);
echo json_encode(["ok" => false, "error" => "Invalid .tinysave document"]);
exit;
}
$game = preg_replace("/[^a-z0-9_-]/i", "", (string)($doc["game"] ?? "game"));
$code = preg_replace("/[^A-Z0-9-]/", "", strtoupper((string)($doc["code"] ?? "")));
if ($game === "" || strlen($code) < 4 || strlen($code) > 32) {
http_response_code(400);
echo json_encode(["ok" => false, "error" => "Invalid game or code"]);
exit;
}
$dir = __DIR__ . "/../data/tinysaves/" . $game;
if (!is_dir($dir) && !mkdir($dir, 0775, true)) {
http_response_code(500);
echo json_encode(["ok" => false, "error" => "Could not create save directory"]);
exit;
}
$target = $dir . "/" . $code . ".tinysave";
file_put_contents($target, json_encode($doc, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES), LOCK_EX);
$logLine = sprintf("[%s] [game:%s] [code:%s] saved .tinysave (%d bytes)\n",
gmdate("Y-m-d H:i:s"), $game, $code, strlen($raw)
);
file_put_contents(__DIR__ . "/../data/tinysave_events.log", $logLine, FILE_APPEND | LOCK_EX);
echo json_encode(["ok" => true, "saved" => $game . "/" . $code . ".tinysave"]);
Python File · tinysave_inspect.py
# File: /opt/tinyfiles/tinysave_inspect.py
import json
import sys
from pathlib import Path
def main() -> None:
if len(sys.argv) < 2:
print("Usage: python3 tinysave_inspect.py <path-to-file.tinysave>")
sys.exit(1)
path = Path(sys.argv[1])
doc = json.loads(path.read_text(encoding="utf-8"))
if doc.get("format") != "tinysave":
raise ValueError("Expected format == 'tinysave'")
print(f"File: {path.name}")
print(f"Game: {doc.get('game')} (v{doc.get('version')})")
print(f"Code: {doc.get('code') or '(none)'}")
print(f"SavedAt: {doc.get('savedAt')}")
print(f"Sum: {doc.get('sum')}")
print("State:", json.dumps(doc.get("state", {}), indent=2))
if __name__ == "__main__":
main()
One Event Log Line · tinysave_events.log
[2026-11-22 07:23:00] [game:ecosystem] [code:TANK-01-ALPHA] exported ecosystem.tinysave (v1)