import { Stats, WriteStream } from 'fs'; import { fs, IFsLocalOptions, IFsUploadOptions, IStat, IWriteStreamOptions, IZipResult } from './interfaces.js'; import { Log } from '@spinajs/log-common'; import archiver from 'archiver'; /** * Abstract layer for file operations. * Basic implementation is just wrapper for native node fs functions * * It allows to wrap other libs eg. aws s3, ftp * and inject it into code without changing logic that use them. * * All failures are surfaced as IOFail ( the original error is preserved as the * inner cause ). When basePath is set, all paths are sandboxed to it - resolved * paths escaping basePath ( eg. via `..` ) throw IOFail. */ export declare class fsNative extends fs { Options: T; protected Logger: Log; /** * Name of provider. We can have multiple providers of the same type but with different options. * Also used in InjectService decorator for mapping */ get Name(): string; get BasePath(): string | undefined; protected zipDestination(): fs; constructor(Options: T); resolve(): Promise; /** * * Tries to download file to local filesystem, then returns local filesystem path. * Native implementation simply returns local path and does nothing. * * @param path - file to download */ protected doDownload(path: string): Promise; protected doUpload(srcPath: string, destPath: string, options?: IFsUploadOptions): Promise; /** * read all content of file */ protected doRead(path: string, encoding?: BufferEncoding): Promise; protected doReadStream(path: string, encoding?: BufferEncoding): Promise; /** * Write to file string or buffer */ protected doWrite(path: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise; protected doAppend(path: string, data: string | Uint8Array, encoding?: BufferEncoding): Promise; /** `options.exclusive` creates missing parent dirs and opens with 'wx', as doUpload's exclusive branch does with COPYFILE_EXCL. */ protected doWriteStream(path: string, rStream: NodeJS.ReadableStream | undefined, options: IWriteStreamOptions): Promise; private exclusiveWriteStream; private openExclusive; /** * Checks if file existst * @param path - path to check */ protected doExists(path: string): Promise; protected doDirExists(path: string): Promise; /** * Copy file or dir to another location * @param path - src path * @param dest - dest path */ protected doCopy(path: string, dest: string, dstFs?: fs): Promise; /** * Copy file to another location and deletes src file */ protected doMove(oldPath: string, newPath: string, dstFs?: fs): Promise; /** * Change name of a file */ protected doRename(oldPath: string, newPath: string): Promise; /** * Native rename seam - extracted so move/rename logic ( eg. EXDEV fallback ) * can be tested without a real cross-device setup. */ protected _rename(oldPath: string, newPath: string): Promise; /** * * Deletes file OR * Deletes dir recursively & all contents inside * * @param path - dir to remove */ protected doRm(path: string): Promise; /** * * Creates directory, recursively * * @param path - directory to create */ protected doMkdir(path: string): Promise; /** * Returns file statistics, not all fields may be accesible */ protected doStat(path: string): Promise; /** * Maps native fs.Stats onto IStat. * * birthtime is the creation time; ctime is inode CHANGE time and would reset * file age on chmod / rename ( breaks temp fs cleanup ageing ). Defensive: * some filesystems report epoch 0 when birthtime is unsupported - fall back * to mtime so age-based logic does not treat files as infinitely old. */ protected toStatEntry(result: Stats): IStat; tmppath(ext?: string): string; /** * List content of directory * * @param path - path to directory */ protected doList(path: string): Promise; protected doUnzip(path: string, destPath: string, dstFs: fs): Promise; protected doIsDir(path: string): Promise; protected doZip(path: string | (string | string[])[], dstFs: fs, dstFile: string): Promise; /** * Source path of a zip entry. Entries are either a plain path or a * [ sourcePath, entryName ] tuple. */ protected zipEntrySource(entry: string | string[]): string; /** * Name a zip entry is stored under: the explicit entry name of a tuple * ( folders kept ), otherwise the base name of the source path. */ protected zipEntryName(entry: string | string[]): string; /** * Fails fast with a single clear error listing every missing source, so a * missing entry never yields a silently incomplete archive. */ protected assertSourcesExist(paths: (string | string[])[]): Promise; /** * Adds every source to the archive - a plain-path directory is added * recursively, everything else as a single file stored under its entry name. */ protected addZipEntries(archive: ReturnType, paths: (string | string[])[]): Promise; /** * Builds the {@link IZipResult} accessor object for a finished archive. * * The zip path is resolved against the DESTINATION fs ( outFile is relative * to its base path ). Remote destinations may not support path resolving - * fall back to the raw name so the accessors still work. */ protected buildZipResult(fs: fs, outFile: string): IZipResult; resolvePath(path: string): string; } //# sourceMappingURL=local-provider.d.ts.map