import { promises as fsp, default as fs } from 'node:fs'; export { fsp }; export type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'utf-16le'; export declare const encodings: readonly ['utf-8', 'gb18030', 'shift-jis', 'utf-16le']; export declare const print_files: { readonly info: true; readonly files: true; }; export declare const print_info: { readonly info: true; readonly files: false; }; export declare const print_info_options: { readonly print: { readonly info: true; readonly files: false; }; }; export declare const binary_encoding: { readonly encoding: 'binary'; }; export declare const binary_noprint: { readonly encoding: 'binary'; readonly print: false; }; export declare const ramdisk: boolean; /** fp 所指向的 文件/ 文件夹 是否存在 - print?: `true` */ export declare function fexists(fp: string, { print }?: { print?: boolean; }): boolean; export interface FileHandle extends fsp.FileHandle { fp: string; flags: string | number; mode?: fs.Mode; } /** 打开或创建文件,返回 FileHandle, 如果文件夹不存在,会自动创建文件夹 Some characters (`< > : " / \ | ? *`) are reserved under Windows as documented by [Naming Files, Paths, and Namespaces](https://docs.microsoft.com/en-us/windows/desktop/FileIO/naming-a-file). Under NTFS, if the filename contains a colon, Node.js will open a file system stream, as described by [this MSDN page](https://docs.microsoft.com/en-us/windows/desktop/FileIO/using-streams). - flags: `'r'` https://nodejs.org/docs/latest/api/fs.html#file-system-flags - options?: - mode?: `'0o666'` 设置新建文件时的 mode (permission and sticky bits) - print?: `false` */ export declare function fopen(fp: string, flags?: string | number, { mode, print }?: { mode?: fs.Mode; print?: boolean; }): Promise; export interface FReadOptions { encoding?: Encoding | 'binary'; print?: boolean; } export declare function fread(fp: string | FileHandle): Promise; export declare function fread(fp: string | FileHandle, options: FReadOptions & { encoding: 'binary'; }): Promise; export declare function fread(fp: string | FileHandle, options?: FReadOptions & { encoding?: Encoding; }): Promise; /** 读取文件,划分为行,并去掉最后一个 \n 之后的 '' */ export declare function fread_lines(fp: string, options?: { dir?: string; encoding?: Encoding; print?: boolean; }): Promise; export declare function fread_json(fp: string, options?: { dir?: string; encoding?: Encoding; print?: boolean; }): Promise; export declare function fparse(fp: string, options?: { print?: boolean; }): Promise; /** 比较两个文件是否一致,遇到任何文件系统错误都返回 false */ export declare function fequals(fp_left: string, fp_right: string, { print }?: { print?: boolean; }): Promise; export interface FWriteOptions { print?: boolean; mtime?: number; flush?: boolean; mode?: fs.Mode; } /** 写入 data 到 fp 路径或句柄所指的文件 会在因不存在父文件夹导致写入失败时,自动创建父文件夹,并再次尝试写入 最好预先创建父文件夹,减少文件系统操作,提升性能 返回写入的文件路径 - fp: 目标文件完整路径或句柄 - data: 支持下面几种类型 - string: 写入文本 - Uint8Array, Buffer: 写入二进制 buffer - any: 通过 JSON.stringify 转为文本后写入文件 - options?: - print?: `true` - mtime?: 在写入后设置修改时间 (utc 毫秒数) - flush?: 用 filehandle.sync() 刷到硬盘,确保已写入 - mode?: 设置 0o755 之类的 mode */ export declare function fwrite(fp: string, data: string | Uint8Array | any, options?: FWriteOptions): Promise; export declare function fwrite(fp: FileHandle, data: string | Uint8Array | any, options?: FWriteOptions): Promise; export declare function fwrite(fp: string | FileHandle, data: string | Uint8Array | any, options?: FWriteOptions): Promise; export declare function fpack(fp: string, data: any, options?: FWriteOptions): Promise; export declare function fpack(fp: FileHandle, data: any, options?: FWriteOptions): Promise; /** 追加内容到文件末尾,如果文件不存在会自动创建 */ export declare function fappend(fp: string, data: string | Uint8Array, { print }?: { print?: boolean; }): Promise; export type FStats = fs.BigIntStats & { fp: string; }; export interface FListOptions { filter?: RegExp | ((fp: string) => any); excludes?: string[] | Set; deep?: boolean; absolute?: boolean; print?: boolean; stats?: boolean; best_effort?: boolean; limit?: number; } interface FListContext { count: number; fpd: string; excludes?: Set; } /** 列出文件夹,默认返回文件名列表,也可以传入 stats 选项返回元数据 - fpd: 文件夹完整路径 - options?: - deep?: `false` 递归遍历 - absolute?: `false` 返回、打印完整路径而不是相对路径,为 false 时返回的 FStats.fp 也会被修改 - print?: `true` - filter?: `() => true` RegExp | (fp: string) => any 注意当 deep = true 时被 filter 过滤掉的目录及目录中的文件不会包含在结果中 - excludes?: 如 ['.git/', 'node_modules/'], 指定忽略的文件、文件夹名称 - stats?: `false` 启用后返回 FStats 列表 - best_effort?: `false` 启用后,当遇到 stat 软链接文件不存在等错误时,会返回一个 fake_time FStats 文件,而不是抛出错误 - limit?: 递归模式下限制最大列出的文件数,达到限制后不再往更深层次递归读取文件夹 */ export declare function flist(fpd: string): Promise; export declare function flist(fpd: string, options?: FListOptions & { stats: true; }, ctx?: FListContext): Promise; export declare function flist(fpd: string, options?: FListOptions, ctx?: FListContext): Promise; export declare function fstat(fp: string | FileHandle): Promise; export declare function flstat(fp: string): Promise; export declare function ffstat(handle: fsp.FileHandle): Promise; /** 删除文件或文件夹,返回是否实际进行了删除操作 - fp: 文件或文件夹的完整路径 - options?: - print?: `true` */ export declare function fdelete(fp: string, { print }?: { print?: boolean; red?: boolean; }): Promise; /** 清空文件夹中的内容,实际为删除该文件夹后新建 */ export declare function fdclear(fpd: string, { print, permission }?: { print?: boolean; permission?: boolean; }): Promise; export interface FCopyOptions { print?: boolean; overwrite?: boolean; filter?: (fp: string) => true | false | 'filter'; } /** 复制文件或文件夹 会在因不存在父文件夹导致复制失败时,自动创建父文件夹,并再次尝试复制 最好预先创建父文件夹,减少文件系统操作,提升性能 - fp_src: 源 文件/文件夹 完整路径 - fp_dst: 目标 文件/文件夹 完整路径 - options?: - print?: `true` - overwrite?: `true` - filter?: 当 fp_src 为文件夹时选择性复制里面的部分内容, 和 flist 的 filter 选项不同,只支持函数,且函数返回值决定是否要继续进行过滤 - true: 复制文件夹的所有文件,交给 fsp.cp - false 或不返回任何值: 不复制 - 'partial': 进一步进行过滤复制(先 flist with filter 再 fcopy),只有文件夹能返回这个值 @example fcopy('D:/temp/camera/', 'D:/camera/') */ export declare function fcopy(fp_src: string, fp_dst: string, { print, overwrite, filter, }?: FCopyOptions): Promise; export interface FMoveOptions { overwrite?: boolean; print?: boolean; } /** 移动文件或文件夹,返回 fp_dst 相同分区 / 文件系统下使用 rename, 否则 fallback 到复制后删除源文件 - src: 源 文件/文件夹 完整路径 - dst: 目标 文件/文件夹 完整路径 - options?: - print?: `true` - overwrite?: `false` @example fmove('D:/temp/camera/', 'D:/camera/') */ export declare function fmove(fp_src: string, fp_dst: string, { overwrite, print }?: FMoveOptions): Promise; /** 重命名文件 rename file - fp: 当前文件名/路径 current filename/path - fp_: 新的文件名/路径 new filename/path - options?: - fpd?: fp 和 fp_ 在同一文件夹内 fp and fp_ is in same directory - print?: `true` - overwrite?: `true` 默认覆盖(不检查效率更高) better performance without check */ export declare function frename(fp: string, fp_: string, { fpd, print, overwrite }?: { fpd?: string; print?: boolean; overwrite?: boolean; }): Promise; export interface FMkdirOptions { print?: boolean; } /** 递归创建文件夹,确保 fpd 指向的文件夹存在 Create folders recursively, make sure the folder pointed to by fpd exists 返回首个创建的文件夹或 undefined Returns the first created folder or undefined - fpd: 文件夹完整路径 Folder full path - options?: - print?: `true` */ export declare function fmkdir(fpd: string, { print }?: FMkdirOptions): Promise; /** 创建软链接 - fp_link: 创建的链接的路径 - fp_real: 真实目标文件/文件夹的路径 - options?: - skip_existing?: `false` 忽略已存在的同名的文件,文件夹 - print?: `true` - junction? */ export declare function flink(fp_link: string, fp_real: string, { skip_existing, print, junction }?: { skip_existing?: boolean; print?: boolean; junction?: boolean; }): Promise; export declare let fwatchers: Record; /** 打开一个文件并使用 .replaceAll 搜索替换某个 pattern */ export declare function freplace(fp: string, pattern: string | RegExp, replacement: string | ((substring: string, ...args: any[]) => string), { print }?: { print?: boolean; }): Promise; /** 根据对象的 fp 属性进行字典序排序 */ export declare function fp_sorter(l: { fp: string; }, r: { fp: string; }): -1 | 0 | 1; export declare function log_action(action: string, fp_src: string, fp_dst: string, sep?: string): void; export interface FBriefFStats { fp: string; size: number; mtime: number; } export declare const to_brief_stats: ({ fp, size, mtimeMs }: FStats) => { fp: string; size: number; mtime: number; };