Skip to main content
Cloudflare Workers run at the edge with no persistent filesystem. Archil gives your Workers read/write access to S3-backed storage using the TypeScript SDK, so you can store and retrieve files without managing object storage APIs directly.

Install the SDK

Add the Archil packages to your Worker project:
npm install @archildata/client @archildata/just-bash

Worker example

This Worker reads and writes files on an Archil disk:
import { ArchilClient } from "@archildata/client";
import { ArchilFs } from "@archildata/just-bash";

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const client = await ArchilClient.connect({
      region: "aws-us-east-1",
      diskName: "myorg/mydisk",
      authToken: env.ARCHIL_DISK_TOKEN,
    });
    const fs = await ArchilFs.create(client);

    try {
      const url = new URL(request.url);

      if (request.method === "PUT") {
        const body = await request.text();
        await fs.writeFile(url.pathname, body);
        return new Response("OK", { status: 200 });
      }

      // GET: read the file
      const content = await fs.readFile(url.pathname);
      return new Response(content, { status: 200 });
    } catch (err: any) {
      return new Response(err.message, { status: 500 });
    } finally {
      await client.close();
    }
  },
};

interface Env {
  ARCHIL_DISK_TOKEN: string;
}

Configuration

Set your Archil token as a secret in your Worker:
npx wrangler secret put ARCHIL_DISK_TOKEN
In your wrangler.toml, enable the Node.js compatibility flag since the SDK uses native bindings:
compatibility_flags = ["nodejs_compat"]

Archil with R2

If you’re already using Cloudflare R2 for object storage, you can use R2 as Archil’s data source. This means Archil caches your R2 data on fast SSD storage close to your compute, giving you a filesystem interface on top of R2 with automatic cache management. Create a disk backed by your R2 bucket and your Workers get fast, cached access to the same data that’s stored in R2.

Performance tips

  • Reuse connections where possible. Each connect() call establishes a new session. For Workers that handle many requests, consider connection reuse patterns.
  • Choose the right region. Pick an Archil region close to the Cloudflare data centers serving your traffic to minimize round-trip latency.
  • Keep payloads reasonable. Workers have CPU time limits. For large file transfers, stream data or process it in chunks rather than reading entire files into memory.