Skip to content

The ObjectStore interface

Everything in git-fs-s3 is built on one small interface. createGitFs doesn’t know or care whether the bytes underneath come from R2, S3, memory, or something else entirely — it only calls these five methods.

interface ObjectStore {
get(key: string): Promise<Uint8Array | null>;
put(key: string, data: Uint8Array): Promise<void>;
delete(key: string): Promise<void>;
head(key: string): Promise<ObjectStat | null>;
list(prefix: string, options?: ListOptions): Promise<ListResult>;
}
functionget
get(key: string): Promise<Uint8Array | null>
ParameterTypeDescription
keystringThe full object key.

Returns: Uint8Array | null

The object’s bytes, or null if the key doesn’t exist. Never throws for a missing key.

functionput
put(key: string, data: Uint8Array): Promise<void>
ParameterTypeDescription
keystringThe full object key.
dataUint8ArrayThe bytes to store.

Writes (or overwrites) an object. Object storage has no atomic multi-key transactions — a caller that needs several keys to become visible together needs its own coordination (see Semantics & limitations).

functiondelete
delete(key: string): Promise<void>
ParameterTypeDescription
keystringThe full object key.

Removes an object. Deleting a key that doesn’t exist is not an error.

functionlist
list(prefix: string, options?: ListOptions): Promise<ListResult>
ParameterTypeDescription
prefixstringOnly keys starting with this prefix.
options?ListOptionsdelimiter (directory-style grouping) and limit.

Returns: ListResult

{ objects: { key, size }[], prefixes: string[] }. When options.delimiter is set (git-fs-s3 always uses "/"), keys are grouped: anything after the first delimiter past prefix collapses into one entry in prefixes instead of appearing in objects — this is what makes readdir() work against storage that has no real directories.

Implement the interface above for any backend and pass it straight to createGitFs — every other piece (caching, retry, the git-aware layer, /http, /ops) works unmodified on top of it.

MemoryObjectStore (exported from the root package) is the reference implementation — read it first. It’s also the store used throughout this package’s own test suite, and the one you’ll reach for in yours:

import { createGitFs, MemoryObjectStore } from 'git-fs-s3';
const fs = createGitFs(new MemoryObjectStore());

The one storage backend shipped out of the box, over @aws-sdk/client-s3 (an optional peer dependency, loaded only via the /s3 subpath so consumers who don’t need it don’t pay for it).

import { S3ObjectStore } from 'git-fs-s3/s3';
const store = new S3ObjectStore({
client, // reuse one S3Client — see the note below
bucket: 'my-git-repos',
prefix: 'repos/', // optional: a fixed prefix under every key
contentType: (key) =>
/\/(HEAD|config)$|\/refs\//.test(key) ? 'text/plain' : undefined,
});