fs-s3 Extension

Provides filesystem operations for S3-compatible object storage. Alternative to the core fs extension for cloud storage scenarios. Supports AWS S3, Cloudflare R2, MinIO, and other S3-compatible services. Scripts use the same 12-function API regardless of backend — hosts swap implementations without changing script code.

Use S3 fs backend for cloud deployments, serverless environments, multi-region data access, or when working with existing S3 infrastructure. Use core fs for local file operations or single-machine deployments.

Quick Start

import { createRuntimeContext, prefixFunctions } from '@rcrsr/rill';
import { createS3FsExtension } from '@rcrsr/rill-ext-fs-s3';

const ext = createS3FsExtension({
  mounts: {
    data: {
      mode: 'read-write',
      region: 'us-east-1',
      bucket: 'my-app-data',
      credentials: {
        accessKeyId: process.env.AWS_ACCESS_KEY_ID,
        secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY
      }
    }
  }
});
const functions = prefixFunctions('fs', ext);
const ctx = createRuntimeContext({ functions });

// Script: fs::read("data", "report.txt")

Configuration

interface S3FsConfig {
  mounts: Record<string, S3FsMountConfig>;
  maxFileSize?: number;  // bytes (default: 10485760 = 10MB)
  encoding?: 'utf-8' | 'utf8' | 'ascii';
}

interface S3FsMountConfig {
  mode: 'read-only' | 'read-write';
  region: string;
  bucket: string;
  prefix?: string;  // object key prefix
  credentials: {
    accessKeyId: string;
    secretAccessKey: string;
  };
  endpoint?: string;  // for S3-compatible services (MinIO, R2)
  forcePathStyle?: boolean;  // use path-style addressing (required for MinIO)
  glob?: string;  // file filter pattern
  maxFileSize?: number;
}
ParameterTypeDefaultDescription
mountsRecordNamed mount configurations (required)
maxFileSizenumber10485760Maximum file size in bytes
encodingstring'utf-8'File content encoding

Mount parameters:

ParameterTypeDefaultDescription
modestringAccess mode: 'read-only' or 'read-write' (required)
regionstringAWS region or 'auto' for R2 (required)
bucketstringS3 bucket name (required)
prefixstringObject key prefix for namespace isolation
credentialsobjectAWS credentials (required)
endpointstringCustom endpoint for S3-compatible services
forcePathStylebooleanfalsePath-style addressing (required for MinIO)
globstringFile filter pattern

Cloudflare R2:

const ext = createS3FsExtension({
  mounts: {
    storage: {
      mode: 'read-write',
      region: 'auto',
      bucket: 'my-r2-bucket',
      credentials: {
        accessKeyId: process.env.R2_ACCESS_KEY_ID,
        secretAccessKey: process.env.R2_SECRET_ACCESS_KEY
      },
      endpoint: `https://<account-id>.r2.cloudflarestorage.com`
    }
  }
});

MinIO:

const ext = createS3FsExtension({
  mounts: {
    local: {
      mode: 'read-write',
      region: 'us-east-1',
      bucket: 'test-bucket',
      credentials: {
        accessKeyId: 'minioadmin',
        secretAccessKey: 'minioadmin'
      },
      endpoint: 'http://localhost:9000',
      forcePathStyle: true  // MinIO requires path-style addressing
    }
  }
});

Key Differences from Core fs

  • endpoint option enables S3-compatible services beyond AWS (MinIO, Cloudflare R2, DigitalOcean Spaces)
  • forcePathStyle: true required for services using path-style bucket addressing (http://host/bucket/key instead of http://bucket.host/key)
  • prefix option maps mount paths to S3 object key prefixes for namespace isolation within buckets
  • Object keys replace filesystem paths, enabling cloud-native storage patterns

Functions

Provides the same 12 functions as the core fs extension:

FunctionParametersReturnsDescription
readmount, pathstringRead file contents
writemount, path, contentstringWrite file (bytes written)
appendmount, path, contentstringAppend to file (bytes written)
listmount, path?listDirectory contents
findmount, pattern?listRecursive file search with glob
existsmount, pathboolCheck file existence
removemount, pathboolDelete file
statmount, pathdictFile metadata
mkdirmount, pathboolCreate directory
copymount, src, destboolCopy file within mount
movemount, src, destboolMove file within mount
mountslistList configured mounts

Namespace convention: fs or s3

See Also