Documentation
¶
Overview ¶
Package filecache is the content-addressed blob store edvabe uses for template file contexts.
The E2B SDK's Template.build() tars each COPY/copyItems step's source paths client-side, computes a hash over the file contents and metadata, and asks the server via GET /templates/{id}/files/{hash} whether the blob is already present. On a miss, the server hands back a short-lived upload URL; the SDK PUTs the tar there. The hash is not a SHA-256 of the tar stream — it incorporates relative paths, file modes, sizes, and a COPY instruction prefix — so the server stores blobs keyed by this opaque hash without re-verifying. Cache is deduplicated across templates — two templates that COPY the same files share a single on-disk blob.
The on-disk layout is flat: <root>/<hash>.tar. Writes are atomic via a .part sidecar that's renamed into place on success, so a crash or a concurrent Put never leaves a reader seeing a half-written blob.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrHashMismatch = errors.New("filecache: hash mismatch")
ErrHashMismatch is kept for API compatibility but is no longer returned by Put — the SDK's hash is computed over file metadata, not the tar stream, so server-side re-verification is not possible.
var ErrInvalidToken = errors.New("filecache: invalid upload token")
ErrInvalidToken is returned when a token fails signature or expiry verification. Callers should map this to HTTP 401.
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a content-addressed blob store rooted at Root. The zero value is not usable; construct with New.
func New ¶
New constructs a Cache with the given root directory. The directory is created if it does not already exist.
func (*Cache) Has ¶
Has reports whether the given blob exists in the cache. Returns an error only for I/O problems, not for a missing blob (which returns false, nil).
func (*Cache) Open ¶
func (c *Cache) Open(hash string) (io.ReadCloser, error)
Open returns a reader over the cached blob. Caller must close the returned reader. Returns os.ErrNotExist if the blob is not in the cache.
func (*Cache) Put ¶
Put writes the reader's bytes into the cache under the given hash. Put is idempotent: if the blob is already present, the existing file is kept and the input reader is drained but not used. The hash is treated as an opaque client-supplied key — the SDK computes it over file contents, paths, and modes, not over the tar stream, so the server does not re-verify.
type Signer ¶
type Signer struct {
// contains filtered or unexported fields
}
Signer mints and verifies short-lived upload tokens for the content-addressed file cache.
The SDK workflow: edvabe's GET /templates/{id}/files/{hash} handler returns a URL that embeds a signed token. The SDK POSTs the tar to that URL; edvabe's upload handler verifies the token before writing to the cache. This keeps the upload path from needing an authenticated session while still preventing arbitrary upload spam.
Token format: "<base64(hmac)>.<expiryUnix>". HMAC is over "<hash>.<expiryUnix>" using a process-local secret generated once at startup.
func NewRandomSigner ¶
NewRandomSigner seeds the signer with a fresh random secret. Tokens minted by one process instance cannot be verified by another — this is deliberate. The upload path is ephemeral and has no reason to survive a restart.
func NewSigner ¶
func NewSigner(opts SignerOptions) *Signer
NewSigner returns a Signer. A non-nil secret is required for deterministic verification — NewRandomSigner is the convenience for production.