{"file":"server/src/blobs.ts","version":318,"total":237,"from":1,"to":237,"lines":[{"n":1,"text":"// Binary files' bytes (#27), content-addressed by SHA-256, kept in the","atom":"a1482","author":"speed","version":150},{"n":2,"text":"// project's own Durable Object SQLite: 1 MB rows, so a blob is never larger","atom":"a1482","author":"speed","version":150},{"n":3,"text":"// than a row allows, and hasBlob is a synchronous lookup the engine can call.","atom":"a1482","author":"speed","version":150},{"n":4,"text":"// Uploads stream in (a Durable Object RPC message stops at 32 MiB) and are","atom":"a1482","author":"speed","version":150},{"n":5,"text":"// hashed as they arrive; a blob whose bytes don't match its name isn't kept.","atom":"a1482","author":"speed","version":150},{"n":6,"text":"import { createHash } from \"node:crypto\";","atom":"a1482","author":"speed","version":150},{"n":7,"text":"import type { SqliteStorage } from \"./engine-project.ts\";","atom":"a1482","author":"speed","version":150},{"n":8,"text":"","atom":"a1482","author":"speed","version":150},{"n":9,"text":"/** Per file. The push out to Artifacts holds a tree in memory, and a Durable Object has 128 MB. */","atom":"a1482","author":"speed","version":150},{"n":10,"text":"export const BLOB_MAX = 20 * 1024 * 1024;","atom":"a1482","author":"speed","version":150},{"n":11,"text":"const PART = 1024 * 1024;","atom":"a1482","author":"speed","version":150},{"n":12,"text":"const SHA = /^[0-9a-f]{64}$/;","atom":"a1482","author":"speed","version":150},{"n":13,"text":"const SCHEMA =","atom":"a1482","author":"speed","version":150},{"n":14,"text":"\t\"CREATE TABLE blobs (sha TEXT NOT NULL, part INTEGER NOT NULL, data BLOB NOT NULL, PRIMARY KEY (sha, part))\";","atom":"a1482","author":"speed","version":150},{"n":15,"text":"","atom":"a1482","author":"speed","version":150},{"n":16,"text":"const normalizedSchema = (sql: string) => sql.replace(/\\s+/g, \" \").trim().toUpperCase();","atom":"a1482","author":"speed","version":150},{"n":17,"text":"","atom":"a1482","author":"speed","version":150},{"n":18,"text":"export type PutBlob =","atom":"a1482","author":"speed","version":150},{"n":19,"text":"\t| { status: 200; body: { sha256: string; size: number; stored: boolean } }","atom":"a1482","author":"speed","version":150},{"n":20,"text":"\t| { status: 400 | 413; body: { error: string } };","atom":"a1482","author":"speed","version":150},{"n":21,"text":"","atom":"a1482","author":"speed","version":150},{"n":22,"text":"export class BlobStore {","atom":"a1482","author":"speed","version":150},{"n":23,"text":"\tprivate storage: SqliteStorage;","atom":"a1482","author":"speed","version":150},{"n":24,"text":"","atom":"a1482","author":"speed","version":150},{"n":25,"text":"\tconstructor(storage: SqliteStorage) {","atom":"a1482","author":"speed","version":150},{"n":26,"text":"\t\tthis.storage = storage;","atom":"a1482","author":"speed","version":150},{"n":27,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":28,"text":"","atom":"a1482","author":"speed","version":150},{"n":29,"text":"\t/** Reads must not create storage, including when a cold object has no blobs. */","atom":"a1482","author":"speed","version":150},{"n":30,"text":"\tprivate hasSchema(): boolean {","atom":"a1482","author":"speed","version":150},{"n":31,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT type, sql FROM sqlite_master WHERE name = 'blobs'\").toArray() as {","atom":"a1482","author":"speed","version":150},{"n":32,"text":"\t\t\ttype: string;","atom":"a1482","author":"speed","version":150},{"n":33,"text":"\t\t\tsql: string | null;","atom":"a1482","author":"speed","version":150},{"n":34,"text":"\t\t}[];","atom":"a1482","author":"speed","version":150},{"n":35,"text":"\t\tif (rows.length === 0) return false;","atom":"a1482","author":"speed","version":150},{"n":36,"text":"\t\tif (","atom":"a1482","author":"speed","version":150},{"n":37,"text":"\t\t\trows.length !== 1 ||","atom":"a1482","author":"speed","version":150},{"n":38,"text":"\t\t\trows[0]?.type !== \"table\" ||","atom":"a1482","author":"speed","version":150},{"n":39,"text":"\t\t\ttypeof rows[0].sql !== \"string\" ||","atom":"a1482","author":"speed","version":150},{"n":40,"text":"\t\t\tnormalizedSchema(rows[0].sql) !== normalizedSchema(SCHEMA)","atom":"a1482","author":"speed","version":150},{"n":41,"text":"\t\t)","atom":"a1482","author":"speed","version":150},{"n":42,"text":"\t\t\tthrow new Error(\"unsupported blob storage schema\");","atom":"a1482","author":"speed","version":150},{"n":43,"text":"\t\treturn true;","atom":"a1482","author":"speed","version":150},{"n":44,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":45,"text":"","atom":"a1482","author":"speed","version":150},{"n":46,"text":"\t/** Only mutation paths may initialize the exact supported table. Never repair a mismatch. */","atom":"a1482","author":"speed","version":150},{"n":47,"text":"\tprivate ensureSchema(): void {","atom":"a1482","author":"speed","version":150},{"n":48,"text":"\t\tif (!this.hasSchema()) this.storage.sql.exec(SCHEMA);","atom":"a1482","author":"speed","version":150},{"n":49,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":50,"text":"","atom":"a1482","author":"speed","version":150},{"n":51,"text":"\t/** Blobs in sha order after `after`, with their sizes (temporary uploads left out). */","atom":"a1482","author":"speed","version":150},{"n":52,"text":"\tlist(after: string, limit: number): { blobs: { sha: string; size: number }[]; next: string | null } {","atom":"a1482","author":"speed","version":150},{"n":53,"text":"\t\tif (!this.hasSchema()) return { blobs: [], next: null };","atom":"a1482","author":"speed","version":150},{"n":54,"text":"\t\tconst rows = this.storage.sql","atom":"a1482","author":"speed","version":150},{"n":55,"text":"\t\t\t.exec(","atom":"a1482","author":"speed","version":150},{"n":56,"text":"\t\t\t\t\"SELECT sha, SUM(LENGTH(data)) AS size FROM blobs WHERE sha > ? AND sha NOT LIKE 'tmp-%' GROUP BY sha ORDER BY sha LIMIT ?\",","atom":"a1482","author":"speed","version":150},{"n":57,"text":"\t\t\t\tafter,","atom":"a1482","author":"speed","version":150},{"n":58,"text":"\t\t\t\tlimit + 1,","atom":"a1482","author":"speed","version":150},{"n":59,"text":"\t\t\t)","atom":"a1482","author":"speed","version":150},{"n":60,"text":"\t\t\t.toArray() as { sha: string; size: number }[];","atom":"a1482","author":"speed","version":150},{"n":61,"text":"\t\tconst more = rows.length > limit;","atom":"a1482","author":"speed","version":150},{"n":62,"text":"\t\tconst blobs = rows.slice(0, limit);","atom":"a1482","author":"speed","version":150},{"n":63,"text":"\t\treturn { blobs, next: more ? blobs.at(-1)!.sha : null };","atom":"a1482","author":"speed","version":150},{"n":64,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":65,"text":"","atom":"a1482","author":"speed","version":150},{"n":66,"text":"\thas(sha: string): boolean {","atom":"a1482","author":"speed","version":150},{"n":67,"text":"\t\treturn (","atom":"a1482","author":"speed","version":150},{"n":68,"text":"\t\t\tthis.hasSchema() &&","atom":"a1482","author":"speed","version":150},{"n":69,"text":"\t\t\tSHA.test(sha) &&","atom":"a1482","author":"speed","version":150},{"n":70,"text":"\t\t\tthis.storage.sql.exec(\"SELECT 1 FROM blobs WHERE sha = ? LIMIT 1\", sha).toArray().length > 0","atom":"a1482","author":"speed","version":150},{"n":71,"text":"\t\t);","atom":"a1482","author":"speed","version":150},{"n":72,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":73,"text":"","atom":"a1482","author":"speed","version":150},{"n":74,"text":"\t/** Every byte, for the push out. Blobs are at most BLOB_MAX. */","atom":"a1482","author":"speed","version":150},{"n":75,"text":"\tread(sha: string): Uint8Array | null {","atom":"a1482","author":"speed","version":150},{"n":76,"text":"\t\tif (!this.hasSchema()) return null;","atom":"a1482","author":"speed","version":150},{"n":77,"text":"\t\tconst rows = this.storage.sql.exec(\"SELECT data FROM blobs WHERE sha = ? ORDER BY part\", sha).toArray() as {","atom":"a1482","author":"speed","version":150},{"n":78,"text":"\t\t\tdata: ArrayBuffer;","atom":"a1482","author":"speed","version":150},{"n":79,"text":"\t\t}[];","atom":"a1482","author":"speed","version":150},{"n":80,"text":"\t\tif (rows.length === 0) return null;","atom":"a1482","author":"speed","version":150},{"n":81,"text":"\t\tconst out = new Uint8Array(rows.reduce((n, r) => n + r.data.byteLength, 0));","atom":"a1482","author":"speed","version":150},{"n":82,"text":"\t\tlet at = 0;","atom":"a1482","author":"speed","version":150},{"n":83,"text":"\t\tfor (const r of rows) {","atom":"a1482","author":"speed","version":150},{"n":84,"text":"\t\t\tout.set(new Uint8Array(r.data), at);","atom":"a1482","author":"speed","version":150},{"n":85,"text":"\t\t\tat += r.data.byteLength;","atom":"a1482","author":"speed","version":150},{"n":86,"text":"\t\t}","atom":"a1482","author":"speed","version":150},{"n":87,"text":"\t\treturn out;","atom":"a1482","author":"speed","version":150},{"n":88,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":89,"text":"","atom":"a1482","author":"speed","version":150},{"n":90,"text":"\t/** The bytes as a stream, one row at a time, or null. */","atom":"a1482","author":"speed","version":150},{"n":91,"text":"\tstream(sha: string): ReadableStream<Uint8Array> | null {","atom":"a1482","author":"speed","version":150},{"n":92,"text":"\t\tif (!this.has(sha)) return null;","atom":"a1482","author":"speed","version":150},{"n":93,"text":"\t\tconst parts = (","atom":"a1482","author":"speed","version":150},{"n":94,"text":"\t\t\tthis.storage.sql.exec(\"SELECT part FROM blobs WHERE sha = ? ORDER BY part\", sha).toArray() as { part: number }[]","atom":"a1482","author":"speed","version":150},{"n":95,"text":"\t\t).map((r) => r.part);","atom":"a1482","author":"speed","version":150},{"n":96,"text":"\t\tlet i = 0;","atom":"a1482","author":"speed","version":150},{"n":97,"text":"\t\treturn new ReadableStream<Uint8Array>({","atom":"a1482","author":"speed","version":150},{"n":98,"text":"\t\t\tpull: (c) => {","atom":"a1482","author":"speed","version":150},{"n":99,"text":"\t\t\t\tif (i >= parts.length) return c.close();","atom":"a1482","author":"speed","version":150},{"n":100,"text":"\t\t\t\tconst [row] = this.storage.sql","atom":"a1482","author":"speed","version":150},{"n":101,"text":"\t\t\t\t\t.exec(\"SELECT data FROM blobs WHERE sha = ? AND part = ?\", sha, parts[i++]!)","atom":"a1482","author":"speed","version":150},{"n":102,"text":"\t\t\t\t\t.toArray() as { data: ArrayBuffer }[];","atom":"a1482","author":"speed","version":150},{"n":103,"text":"\t\t\t\tc.enqueue(new Uint8Array(row!.data));","atom":"a1482","author":"speed","version":150},{"n":104,"text":"\t\t\t},","atom":"a1482","author":"speed","version":150},{"n":105,"text":"\t\t});","atom":"a1482","author":"speed","version":150},{"n":106,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":107,"text":"","atom":"a1482","author":"speed","version":150},{"n":108,"text":"\t/**","atom":"a1482","author":"speed","version":150},{"n":109,"text":"\t * A whole file's text (#46), stored as UTF-8 under its SHA-256. Synchronous,","atom":"a1482","author":"speed","version":150},{"n":110,"text":"\t * so the engine can call it while it records.","atom":"a1482","author":"speed","version":150},{"n":111,"text":"\t */","atom":"a1482","author":"speed","version":150},{"n":112,"text":"\tputText(text: string): string {","atom":"a1482","author":"speed","version":150},{"n":113,"text":"\t\tconst bytes = new TextEncoder().encode(text);","atom":"a1482","author":"speed","version":150},{"n":114,"text":"\t\tconst sha = createHash(\"sha256\").update(bytes).digest(\"hex\");","atom":"a1482","author":"speed","version":150},{"n":115,"text":"\t\tif (!this.has(sha)) this.write(sha, bytes, 0);","atom":"a1482","author":"speed","version":150},{"n":116,"text":"\t\treturn sha;","atom":"a1482","author":"speed","version":150},{"n":117,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":118,"text":"","atom":"a1482","author":"speed","version":150},{"n":119,"text":"\t/** A whole file's text back, or null. */","atom":"a1482","author":"speed","version":150},{"n":120,"text":"\ttextOf(sha: string): string | null {","atom":"a1482","author":"speed","version":150},{"n":121,"text":"\t\tconst bytes = this.read(sha);","atom":"a1482","author":"speed","version":150},{"n":122,"text":"\t\treturn bytes ? new TextDecoder().decode(bytes) : null;","atom":"a1482","author":"speed","version":150},{"n":123,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":124,"text":"","atom":"a1482","author":"speed","version":150},{"n":125,"text":"\t/** Stores bytes already in memory (plain-git intake), under their own hash. */","atom":"a1482","author":"speed","version":150},{"n":126,"text":"\tasync putBytes(bytes: Uint8Array): Promise<string> {","atom":"a1482","author":"speed","version":150},{"n":127,"text":"\t\tconst sha = hex(await crypto.subtle.digest(\"SHA-256\", bytes));","atom":"a1482","author":"speed","version":150},{"n":128,"text":"\t\tif (!this.has(sha)) this.write(sha, bytes, 0);","atom":"a1482","author":"speed","version":150},{"n":129,"text":"\t\treturn sha;","atom":"a1482","author":"speed","version":150},{"n":130,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":131,"text":"","atom":"a1482","author":"speed","version":150},{"n":132,"text":"\t/** Streams an upload in, checking its size and that its SHA-256 is `sha`. */","atom":"a1482","author":"speed","version":150},{"n":133,"text":"\t/** `max` lowers BLOB_MAX for this put (a capped project's file cap, abso issue 249). */","atom":"a1482","author":"speed","version":150},{"n":134,"text":"\tasync put(sha: string, body: ReadableStream<Uint8Array>, max: number = BLOB_MAX): Promise<PutBlob> {","atom":"a1482","author":"speed","version":150},{"n":135,"text":"\t\tif (!SHA.test(sha)) return { status: 400, body: { error: \"a blob's name is its SHA-256 in lowercase hex\" } };","atom":"a1482","author":"speed","version":150},{"n":136,"text":"\t\tif (this.has(sha)) {","atom":"a1482","author":"speed","version":150},{"n":137,"text":"\t\t\tawait body.cancel().catch(() => {});","atom":"a1482","author":"speed","version":150},{"n":138,"text":"\t\t\treturn { status: 200, body: { sha256: sha, size: this.size(sha), stored: false } };","atom":"a1482","author":"speed","version":150},{"n":139,"text":"\t\t}","atom":"a1482","author":"speed","version":150},{"n":140,"text":"\t\tconst temp = `tmp-${crypto.randomUUID()}`;","atom":"a1482","author":"speed","version":150},{"n":141,"text":"\t\tconst digest = new crypto.DigestStream(\"SHA-256\");","atom":"a1482","author":"speed","version":150},{"n":142,"text":"\t\tconst hashing = digest.getWriter();","atom":"a1482","author":"speed","version":150},{"n":143,"text":"\t\tlet size = 0;","atom":"a1482","author":"speed","version":150},{"n":144,"text":"\t\tlet part = 0;","atom":"a1482","author":"speed","version":150},{"n":145,"text":"\t\tlet pending: Uint8Array[] = [];","atom":"a1482","author":"speed","version":150},{"n":146,"text":"\t\tlet pendingSize = 0;","atom":"a1482","author":"speed","version":150},{"n":147,"text":"\t\tconst flush = () => {","atom":"a1482","author":"speed","version":150},{"n":148,"text":"\t\t\tif (pendingSize === 0) return;","atom":"a1482","author":"speed","version":150},{"n":149,"text":"\t\t\tpart = this.write(temp, concat(pending, pendingSize), part);","atom":"a1482","author":"speed","version":150},{"n":150,"text":"\t\t\tpending = [];","atom":"a1482","author":"speed","version":150},{"n":151,"text":"\t\t\tpendingSize = 0;","atom":"a1482","author":"speed","version":150},{"n":152,"text":"\t\t};","atom":"a1482","author":"speed","version":150},{"n":153,"text":"\t\ttry {","atom":"a1482","author":"speed","version":150},{"n":154,"text":"\t\t\tfor await (const chunk of body) {","atom":"a1482","author":"speed","version":150},{"n":155,"text":"\t\t\t\tsize += chunk.byteLength;","atom":"a1482","author":"speed","version":150},{"n":156,"text":"\t\t\t\tif (size > max) {","atom":"a1482","author":"speed","version":150},{"n":157,"text":"\t\t\t\t\tthis.drop(temp);","atom":"a1482","author":"speed","version":150},{"n":158,"text":"\t\t\t\t\treturn { status: 413, body: { error: `blobs are at most ${max / 1024 / 1024} MB` } };","atom":"a1482","author":"speed","version":150},{"n":159,"text":"\t\t\t\t}","atom":"a1482","author":"speed","version":150},{"n":160,"text":"\t\t\t\tawait hashing.write(chunk);","atom":"a1482","author":"speed","version":150},{"n":161,"text":"\t\t\t\tpending.push(chunk);","atom":"a1482","author":"speed","version":150},{"n":162,"text":"\t\t\t\tpendingSize += chunk.byteLength;","atom":"a1482","author":"speed","version":150},{"n":163,"text":"\t\t\t\tif (pendingSize >= PART) flush();","atom":"a1482","author":"speed","version":150},{"n":164,"text":"\t\t\t}","atom":"a1482","author":"speed","version":150},{"n":165,"text":"\t\t\tflush();","atom":"a1482","author":"speed","version":150},{"n":166,"text":"\t\t\tif (part === 0) part = this.write(temp, new Uint8Array(), 0); // an empty file is a blob too","atom":"a1482","author":"speed","version":150},{"n":167,"text":"\t\t\tawait hashing.close();","atom":"a1482","author":"speed","version":150},{"n":168,"text":"\t\t\tconst got = hex(await digest.digest);","atom":"a1482","author":"speed","version":150},{"n":169,"text":"\t\t\tif (got !== sha) {","atom":"a1482","author":"speed","version":150},{"n":170,"text":"\t\t\t\tthis.drop(temp);","atom":"a1482","author":"speed","version":150},{"n":171,"text":"\t\t\t\treturn { status: 400, body: { error: `the bytes hash to ${got}, not ${sha}` } };","atom":"a1482","author":"speed","version":150},{"n":172,"text":"\t\t\t}","atom":"a1482","author":"speed","version":150},{"n":173,"text":"\t\t\t// Another upload of the same bytes may have finished meanwhile.","atom":"a1482","author":"speed","version":150},{"n":174,"text":"\t\t\tif (this.has(sha)) this.drop(temp);","atom":"a1482","author":"speed","version":150},{"n":175,"text":"\t\t\telse {","atom":"a1482","author":"speed","version":150},{"n":176,"text":"\t\t\t\tthis.ensureSchema();","atom":"a1482","author":"speed","version":150},{"n":177,"text":"\t\t\t\tthis.storage.sql.exec(\"UPDATE blobs SET sha = ? WHERE sha = ?\", sha, temp);","atom":"a1482","author":"speed","version":150},{"n":178,"text":"\t\t\t}","atom":"a1482","author":"speed","version":150},{"n":179,"text":"\t\t\treturn { status: 200, body: { sha256: sha, size, stored: true } };","atom":"a1482","author":"speed","version":150},{"n":180,"text":"\t\t} catch (e) {","atom":"a1482","author":"speed","version":150},{"n":181,"text":"\t\t\tthis.drop(temp);","atom":"a1482","author":"speed","version":150},{"n":182,"text":"\t\t\tthrow e;","atom":"a1482","author":"speed","version":150},{"n":183,"text":"\t\t}","atom":"a1482","author":"speed","version":150},{"n":184,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":185,"text":"","atom":"a1482","author":"speed","version":150},{"n":186,"text":"\t/** Every blob's bytes together, referenced or not (a capped project's total, 249). Uploads in progress don't count. */","atom":"a1482","author":"speed","version":150},{"n":187,"text":"\ttotal(): number {","atom":"a1482","author":"speed","version":150},{"n":188,"text":"\t\tif (!this.hasSchema()) return 0;","atom":"a1482","author":"speed","version":150},{"n":189,"text":"\t\tconst [row] = this.storage.sql","atom":"a1482","author":"speed","version":150},{"n":190,"text":"\t\t\t.exec(\"SELECT COALESCE(SUM(LENGTH(data)), 0) AS n FROM blobs WHERE sha NOT LIKE 'tmp-%'\")","atom":"a1482","author":"speed","version":150},{"n":191,"text":"\t\t\t.toArray() as { n: number }[];","atom":"a1482","author":"speed","version":150},{"n":192,"text":"\t\treturn row?.n ?? 0;","atom":"a1482","author":"speed","version":150},{"n":193,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":194,"text":"","atom":"a1482","author":"speed","version":150},{"n":195,"text":"\t/** A blob's size in bytes: 0 when the project doesn't hold it. */","atom":"a1482","author":"speed","version":150},{"n":196,"text":"\tsize(sha: string): number {","atom":"a1482","author":"speed","version":150},{"n":197,"text":"\t\tif (!this.hasSchema()) return 0;","atom":"a1482","author":"speed","version":150},{"n":198,"text":"\t\tconst [row] = this.storage.sql","atom":"a1482","author":"speed","version":150},{"n":199,"text":"\t\t\t.exec(\"SELECT COALESCE(SUM(LENGTH(data)), 0) AS n FROM blobs WHERE sha = ?\", sha)","atom":"a1482","author":"speed","version":150},{"n":200,"text":"\t\t\t.toArray() as { n: number }[];","atom":"a1482","author":"speed","version":150},{"n":201,"text":"\t\treturn row?.n ?? 0;","atom":"a1482","author":"speed","version":150},{"n":202,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":203,"text":"","atom":"a1482","author":"speed","version":150},{"n":204,"text":"\t/** Writes bytes as rows of at most PART from part `first` on; answers the next part. An empty blob is one empty row. */","atom":"a1482","author":"speed","version":150},{"n":205,"text":"\tprivate write(sha: string, bytes: Uint8Array, first: number): number {","atom":"a1482","author":"speed","version":150},{"n":206,"text":"\t\tthis.ensureSchema();","atom":"a1482","author":"speed","version":150},{"n":207,"text":"\t\tlet part = first;","atom":"a1482","author":"speed","version":150},{"n":208,"text":"\t\tfor (let at = 0; at < bytes.byteLength || (at === 0 && part === 0); at += PART) {","atom":"a1482","author":"speed","version":150},{"n":209,"text":"\t\t\tthis.storage.sql.exec(","atom":"a1482","author":"speed","version":150},{"n":210,"text":"\t\t\t\t\"INSERT INTO blobs (sha, part, data) VALUES (?, ?, ?)\",","atom":"a1482","author":"speed","version":150},{"n":211,"text":"\t\t\t\tsha,","atom":"a1482","author":"speed","version":150},{"n":212,"text":"\t\t\t\tpart++,","atom":"a1482","author":"speed","version":150},{"n":213,"text":"\t\t\t\tbytes.slice(at, at + PART),","atom":"a1482","author":"speed","version":150},{"n":214,"text":"\t\t\t);","atom":"a1482","author":"speed","version":150},{"n":215,"text":"\t\t\tif (bytes.byteLength === 0) break;","atom":"a1482","author":"speed","version":150},{"n":216,"text":"\t\t}","atom":"a1482","author":"speed","version":150},{"n":217,"text":"\t\treturn part;","atom":"a1482","author":"speed","version":150},{"n":218,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":219,"text":"","atom":"a1482","author":"speed","version":150},{"n":220,"text":"\tprivate drop(sha: string) {","atom":"a1482","author":"speed","version":150},{"n":221,"text":"\t\tthis.ensureSchema();","atom":"a1482","author":"speed","version":150},{"n":222,"text":"\t\tthis.storage.sql.exec(\"DELETE FROM blobs WHERE sha = ?\", sha);","atom":"a1482","author":"speed","version":150},{"n":223,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":224,"text":"}","atom":"a1482","author":"speed","version":150},{"n":225,"text":"","atom":"a1482","author":"speed","version":150},{"n":226,"text":"function concat(chunks: Uint8Array[], size: number): Uint8Array {","atom":"a1482","author":"speed","version":150},{"n":227,"text":"\tif (chunks.length === 1) return chunks[0]!;","atom":"a1482","author":"speed","version":150},{"n":228,"text":"\tconst out = new Uint8Array(size);","atom":"a1482","author":"speed","version":150},{"n":229,"text":"\tlet at = 0;","atom":"a1482","author":"speed","version":150},{"n":230,"text":"\tfor (const c of chunks) {","atom":"a1482","author":"speed","version":150},{"n":231,"text":"\t\tout.set(c, at);","atom":"a1482","author":"speed","version":150},{"n":232,"text":"\t\tat += c.byteLength;","atom":"a1482","author":"speed","version":150},{"n":233,"text":"\t}","atom":"a1482","author":"speed","version":150},{"n":234,"text":"\treturn out;","atom":"a1482","author":"speed","version":150},{"n":235,"text":"}","atom":"a1482","author":"speed","version":150},{"n":236,"text":"","atom":"a1482","author":"speed","version":150},{"n":237,"text":"const hex = (buf: ArrayBuffer) => [...new Uint8Array(buf)].map((b) => b.toString(16).padStart(2, \"0\")).join(\"\");","atom":"a1482","author":"speed","version":150}],"atoms":[{"atom":"a1482","author":"speed","message":"","time":1791907425388,"timeIso":"2026-10-13T16:03:45.388Z","publish":{"draft":null,"version":150,"agent":"speed","message":"Open server: the project Worker, Durable Object and Artifacts (issue 17)","time":1791907522179,"timeIso":"2026-10-13T16:05:22.179Z"}}]}