MCPcopy Create free account
hub / github.com/UsefulSoftwareCo/executor / putBlobR2

Function putBlobR2

apps/cloud/scripts/migrate-specs-to-blobs.ts:105–123  ·  view source on GitHub ↗
(objectName: string, value: string)

Source from the content-addressed store, hash-verified

103const tempDir = mkdtempSync(join(tmpdir(), "spec-blobs-"));
104
105const putBlobR2 = (objectName: string, value: string): void => {
106 const file = join(tempDir, "blob-upload");
107 writeFileSync(file, value, "utf8");
108 execFileSync(
109 "wrangler",
110 ["r2", "object", "put", `${bucket}/${objectName}`, "--file", file, "--remote"],
111 { stdio: ["ignore", "ignore", "inherit"] },
112 );
113 const verifyFile = join(tempDir, "blob-verify");
114 execFileSync(
115 "wrangler",
116 ["r2", "object", "get", `${bucket}/${objectName}`, "--file", verifyFile, "--remote"],
117 { stdio: ["ignore", "ignore", "inherit"] },
118 );
119 const roundTripped = readFileSync(verifyFile, "utf8");
120 if (sha256Hex(roundTripped) !== sha256Hex(value)) {
121 throw new Error(`R2 round-trip mismatch for ${objectName}`);
122 }
123};
124
125const putBlobDb = async (namespace: string, key: string, value: string): Promise<void> => {
126 const id = fumaBlobId(namespace, key);

Callers 1

Calls 1

sha256HexFunction · 0.70

Tested by

no test coverage detected