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

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        The file identifier/path where file will be created

      • stream: WritableFileAdapterStream

        File content stream with HTTP headers configuration

      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

      • context: IReadableContext

        Readable execution context for the operation

      • source: string

        Source file identifier/path to copy from

      • destination: string

        Destination file identifier/path to copy to

      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

      • context: IReadableContext

        Readable execution context for the operation

      • source: string

        Source file identifier/path to copy from

      • destination: string

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

      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

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        The file identifier/path

      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

      • context: IReadableContext

        Readable execution context for the operation

      • source: string

        Source file identifier/path to move from

      • destination: string

        Destination file identifier/path to move to

      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

      • context: IReadableContext

        Readable execution context for the operation

      • source: string

        Source file identifier/path to move from

      • destination: string

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

      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

      • context: IReadableContext

        Readable execution context for the operation

      • key: string

        The file identifier/path to create or update

      • stream: WritableFileAdapterStream

        File content stream with HTTP headers configuration

      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

      • context: IReadableContext

        Readable execution context for the operation

      • prefix: string

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

      Returns Promise<void>

      Void (always succeeds)

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