IFileStorageAdapter: {
    add(
        key: string,
        content: WritableFileAdapterContent,
        context: IReadableContext,
    ): Promise<boolean>;
    addStream(
        key: string,
        stream: WritableFileAdapterStream,
        context: IReadableContext,
    ): Promise<boolean>;
    copy(
        source: string,
        destination: string,
        context: IReadableContext,
    ): Promise<FileWriteEnum>;
    copyAndReplace(
        source: string,
        destination: string,
        context: IReadableContext,
    ): Promise<boolean>;
    exists(key: string, context: IReadableContext): Promise<boolean>;
    getBytes(
        key: string,
        context: IReadableContext,
    ): Promise<null | Uint8Array<ArrayBufferLike>>;
    getMetaData(
        key: string,
        context: IReadableContext,
    ): Promise<null | FileAdapterMetadata>;
    getStream(
        key: string,
        context: IReadableContext,
    ): Promise<null | FileAdapterStream>;
    move(
        source: string,
        destination: string,
        context: IReadableContext,
    ): Promise<FileWriteEnum>;
    moveAndReplace(
        source: string,
        destination: string,
        context: IReadableContext,
    ): Promise<boolean>;
    put(
        key: string,
        content: WritableFileAdapterContent,
        context: IReadableContext,
    ): Promise<boolean>;
    putStream(
        key: string,
        stream: WritableFileAdapterStream,
        context: IReadableContext,
    ): Promise<boolean>;
    removeByPrefix(prefix: string, context: IReadableContext): Promise<void>;
    removeMany(keys: string[], context: IReadableContext): Promise<boolean>;
    update(
        key: string,
        content: WritableFileAdapterContent,
        context: IReadableContext,
    ): Promise<boolean>;
    updateStream(
        key: string,
        stream: WritableFileAdapterStream,
        context: IReadableContext,
    ): Promise<boolean>;
}

File storage adapter contract defining complete file operations. Abstracts storage backend implementation (local filesystem, S3, database, memory, etc).

IMPORT_PATH: "@daiso-tech/core/file-storage/contracts"

Type declaration

  • add:function
  • addStream:function
    • 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.

      Parameters

      • key: string

        The file identifier/path where file will be created

      • stream: WritableFileAdapterStream

        File content stream with HTTP headers configuration

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<boolean>

      True if file was created, false if key already exists

  • copy:function
    • Copies source file to destination path if destination doesn't exist. Destination is left unchanged if source not found or destination already exists.

      Parameters

      • source: string

        Source file identifier/path to copy from

      • destination: string

        Destination file identifier/path to copy to

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<FileWriteEnum>

      FileWriteEnum indicating: SUCCESS (copied), NOT_FOUND (source missing), or KEY_EXISTS (destination exists)

  • copyAndReplace:function
    • Copies source file to destination path, overwriting destination if it exists. Returns false if source doesn't exist; destination remains unchanged.

      Parameters

      • source: string

        Source file identifier/path to copy from

      • destination: string

        Destination file identifier/path to copy to (will be overwritten)

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<boolean>

      True if source was found and copied, false if source doesn't exist

  • exists:function
  • getBytes:function
    • 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.

      Parameters

      • key: string

        The file identifier/path

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<null | Uint8Array<ArrayBufferLike>>

      Complete file bytes as Uint8Array, or null if file not found

  • getMetaData:function
  • getStream:function
  • move:function
    • 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.

      Parameters

      • source: string

        Source file identifier/path to move from

      • destination: string

        Destination file identifier/path to move to

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<FileWriteEnum>

      FileWriteEnum indicating: SUCCESS (moved), NOT_FOUND (source missing), or KEY_EXISTS (destination exists)

  • moveAndReplace:function
    • 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.

      Parameters

      • source: string

        Source file identifier/path to move from

      • destination: string

        Destination file identifier/path to move to (will be overwritten)

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<boolean>

      True if source was found and moved, false if source doesn't exist

  • put:function
  • putStream:function
    • 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.

      Parameters

      • key: string

        The file identifier/path to create or update

      • stream: WritableFileAdapterStream

        File content stream with HTTP headers configuration

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<boolean>

      True if file was updated (already existed), false if newly created

  • removeByPrefix:function
    • 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.

      Parameters

      • prefix: string

        Key prefix to match (e.g., "uploads/2024-01/" for all January uploads)

      • context: IReadableContext

        Readable execution context for the operation

      Returns Promise<void>

      Void (always succeeds)

  • removeMany:function
  • update:function
  • updateStream:function