UNPKG

@synet/fs-azure

Version:

Azure filesystem abstraction following FileSystem pattern

104 lines (103 loc) 3.13 kB
import type { FileStats, IAsyncFileSystem } from "./filesystem.interface"; /** * Azure Blob Storage filesystem configuration options */ export interface AzureBlobStorageOptions { /** Azure Storage account connection string (recommended for simplicity) */ connectionString?: string; /** Storage account name (alternative to connection string) */ accountName?: string; /** Storage account key (alternative to connection string) */ accountKey?: string; /** Container name (equivalent to S3 bucket) */ containerName: string; /** Base prefix for all operations (acts as root directory) */ prefix?: string; /** Custom blob service endpoint */ blobServiceEndpoint?: string; } /** * Azure Blob Storage-based async filesystem implementation * * Provides filesystem operations on Azure Blob Storage. * Each file operation corresponds to Azure blob operations. * Directories are handled virtually through blob name prefixes. */ export declare class AzureBlobStorageFileSystem implements IAsyncFileSystem { private blobServiceClient; private containerClient; private options; private cache; constructor(options: AzureBlobStorageOptions); /** * Get Azure blob name from filesystem path */ private getAzureBlobName; /** * Get filesystem path from Azure blob name */ private getFilesystemPath; /** * Check if a file exists in Azure Blob Storage */ exists(path: string): Promise<boolean>; /** * Read a file from Azure Blob Storage */ readFile(path: string): Promise<string>; /** * Write a file to Azure Blob Storage */ writeFile(path: string, data: string): Promise<void>; /** * Delete a file from Azure Blob Storage */ deleteFile(path: string): Promise<void>; /** * List directory contents */ readDir(dirPath: string): Promise<string[]>; /** * Ensure directory exists (no-op for blob storage) */ ensureDir(dirPath: string): Promise<void>; /** * Delete directory and all its contents */ deleteDir(dirPath: string): Promise<void>; /** * Change file permissions (no-op for blob storage) */ chmod(path: string, mode: number): Promise<void>; /** * Get file statistics */ stat(path: string): Promise<FileStats>; /** * Clear the internal cache */ clearCache(): void; /** * Get container information */ getContainerInfo(): { containerName: string; prefix: string; hasConnectionString: boolean; hasAccountCredentials: boolean; blobServiceEndpoint: string | undefined; }; /** * Determine content type based on file extension */ private getContentType; /** * Check if error is a "not found" error */ private isNotFoundError; } /** * Create a new Azure Blob Storage filesystem instance * @param options Azure Blob Storage configuration */ export declare function createAzureBlobStorageFileSystem(options: AzureBlobStorageOptions): AzureBlobStorageFileSystem;