import { Base64Codec } from "@daiso-tech/core/codex/base-64-codec";
import { FsFileStorageAdapter } from "@daiso-tech/core/file-storage/fs-file-storage-adapter";
const fileStorageAdapter = new FsFileStorageAdapter({
// Both settings are optional
location: new URL("./uploads", import.meta.url).toString(),
// By default base64 is used for encoding and decoding the filenames,
codec: new Base64Codec()
});
Creates new file at key if it doesn't already exist. Fails if key already exists (use put for upsert or update for existing files). Content is loaded entirely in memory - use addStream for large files.
The file identifier/path where file will be created
File content with HTTP headers configuration
True if file was created, false if key already exists
Creates new file at key using streaming content if it doesn't already exist. Fails if key already exists (use putStream for upsert or updateStream for existing files). Content is streamed - efficient for large files or continuous data sources.
The file identifier/path where file will be created
File content stream with HTTP headers configuration
True if file was created, false if key already exists
Copies source file to destination path if destination doesn't exist. Destination is left unchanged if source not found or destination already exists.
Source file identifier/path to copy from
Destination file identifier/path to copy to
FileWriteEnum indicating: SUCCESS (copied), NOT_FOUND (source missing), or KEY_EXISTS (destination exists)
Copies source file to destination path, overwriting destination if it exists. Returns false if source doesn't exist; destination remains unchanged.
Source file identifier/path to copy from
Destination file identifier/path to copy to (will be overwritten)
True if source was found and copied, false if source doesn't exist
Checks whether a file exists at the given key.
The file identifier/path to check
True if file exists, false otherwise
Retrieves complete file content as a byte array. The entire file must fit in memory - use getStream for large files. Returns null if the file does not exist.
The file identifier/path
Complete file bytes as Uint8Array, or null if file not found
Retrieves file metadata (ETag, content type, size, modification date). Returns null if the file does not exist. Useful for cache validation and file information endpoints.
The file identifier/path
File metadata object, or null if file not found
Retrieves file content as an async stream of byte chunks. Memory-efficient for large files - content is streamed rather than loaded entirely. Returns null if the file does not exist.
The file identifier/path
Async iterable of Uint8Array chunks, or null if file not found
Moves (renames) source file to destination path if destination doesn't exist. Destination is left unchanged if source not found or destination already exists. Effectively deletes the source file after successful copy.
Readable execution context for the operation
Source file identifier/path to move from
Destination file identifier/path to move to
FileWriteEnum indicating: SUCCESS (moved), NOT_FOUND (source missing), or KEY_EXISTS (destination exists)
Moves (renames) source file to destination path, overwriting destination if it exists. Returns false if source doesn't exist; destination remains unchanged. Effectively deletes the source file after successful copy.
Readable execution context for the operation
Source file identifier/path to move from
Destination file identifier/path to move to (will be overwritten)
True if source was found and moved, false if source doesn't exist
Creates or overwrites file (upsert) at key with content. Always succeeds: creates file if doesn't exist, overwrites if exists. Content is loaded entirely in memory - use putStream for large files.
The file identifier/path to create or update
File content with HTTP headers configuration
True if file was updated (already existed), false if newly created
Creates or overwrites file (upsert) at key using streaming content. Always succeeds: creates file if doesn't exist, overwrites if exists. Content is streamed - efficient for large files or continuous data sources.
The file identifier/path to create or update
File content stream with HTTP headers configuration
True if file was updated (already existed), false if newly created
Removes all files whose keys start with the given prefix. Useful for batch deletion by directory or namespace. Silently succeeds if no keys match the prefix.
Key prefix to match (e.g., "uploads/2024-01/" for all January uploads)
Void (always succeeds)
Removes multiple specific files by key.
Array of file identifiers/paths to delete
True if at least one key was deleted, false if no keys were found
Updates existing file at key with new content. Fails if key doesn't exist (use put for upsert or add for new files). Content is loaded entirely in memory - use updateStream for large files.
The file identifier/path to update
New file content with HTTP headers configuration
True if file was updated, false if key doesn't exist
Updates existing file at key using streaming content. Fails if key doesn't exist (use putStream for upsert or addStream for new files). Content is streamed - efficient for large files or continuous data sources.
The file identifier/path to update
New file content stream with HTTP headers configuration
True if file was updated, false if key doesn't exist
The
FsFileStorageAdapteris used for local development when persistence is needed when restarting the dev server. NoteFsFileStorageAdapterlacks nested folder support. A flat hierarchy is used, requiring filename encoding/decoding.IMPORT_PATH:
"@daiso-tech/core/file-storage/fs-file-storage-adapter"