import { promises as fsp, default as fs } from 'node:fs';
import type { UnzipFileFilter } from './fflate.ts';
export { fsp };
export type Encoding = 'utf-8' | 'gb18030' | 'shift-jis' | 'utf-16le';
export type FileHandle = fsp.FileHandle & {
    fp: string;
};
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 ramdisk: boolean;
/** fp 所指向的 文件/ 文件夹 是否存在
    - print?: `true` */
export declare function fexists(fp: string, { print }?: {
    print?: boolean;
}): boolean;
/** 打开或创建文件，返回 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<fsp.FileHandle & {
    fp: string;
    flags: string | number;
    mode: fs.Mode;
}>;
export interface FReadOptions {
    encoding?: Encoding | 'binary';
    print?: boolean;
}
export declare function fread(fp: string | FileHandle): Promise<string>;
export declare function fread(fp: string | FileHandle, options: FReadOptions & {
    encoding: 'binary';
}): Promise<Buffer>;
export declare function fread(fp: string | FileHandle, options?: FReadOptions & {
    encoding?: Encoding;
}): Promise<string>;
/** 读取文件，划分为行，并去掉最后一个 \n 之后的 '' */
export declare function fread_lines(fp: string, options?: {
    dir?: string;
    encoding?: Encoding;
    print?: boolean;
}): Promise<string[]>;
export declare function fread_json<T = any>(fp: string, options?: {
    dir?: string;
    encoding?: Encoding;
    print?: boolean;
}): Promise<T>;
export declare function fparse<TReturn>(fp: string, options?: {
    print?: boolean;
}): Promise<TReturn>;
/** 比较两个文件是否一致，遇到任何文件系统错误都返回 false */
export declare function fequals(fp_left: string, fp_right: string, { print }?: {
    print?: boolean;
}): Promise<boolean>;
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<string>;
export declare function fwrite(fp: FileHandle, data: string | Uint8Array | any, options?: FWriteOptions): Promise<FileHandle>;
export declare function fwrite(fp: string | FileHandle, data: string | Uint8Array | any, options?: FWriteOptions): Promise<string | FileHandle>;
export declare function fpack(fp: string, data: any, options?: FWriteOptions): Promise<string>;
export declare function fpack(fp: FileHandle, data: any, options?: FWriteOptions): Promise<FileHandle>;
/** 追加内容到文件末尾，如果文件不存在会自动创建 */
export declare function fappend(fp: string, data: string | Uint8Array, { print }?: {
    print?: boolean;
}): Promise<void>;
export type FStats = fs.BigIntStats & {
    fp: string;
};
export interface FListOptions {
    filter?: RegExp | ((fp: string) => any);
    deep?: boolean;
    absolute?: boolean;
    print?: boolean;
    stats?: boolean;
    best_effort?: boolean;
}
/** 列出文件夹，默认返回文件名列表，也可以传入 stats 选项返回元数据
    - fpd: 文件夹完整路径 absolute path of directory
    - options?:
        - deep?: `false` 递归遍历 recursively
        - absolute?: `false` 返回、打印完整路径而不是相对路径，为 false 时返回的 FStats.fp 也会被修改 Return, print full path instead of relative path, FStats.fp returned when false will also be modified
        - print?: `true`
        - filter?: `() => true`  RegExp | (fp: string) => any
            注意当 deep = true 时被 filter 过滤掉的目录及目录中的文件不会包含在结果中
        - stats?: `false` 启用后返回 FStats 列表
        - best_effort?: `false` 启用后，当遇到 stat 软链接文件不存在等错误时，会返回一个 fake_time FStats 文件，而不是抛出错误 */
export declare function flist(fpd: string): Promise<string[]>;
export declare function flist(fpd: string, options?: FListOptions & {
    stats: true;
}): Promise<FStats[]>;
export declare function flist(fpd: string, options?: FListOptions): Promise<string[]>;
export declare function fstat(fp: string | FileHandle): Promise<FStats>;
export declare function flstat(fp: string): Promise<FStats>;
export declare function ffstat(handle: fsp.FileHandle): Promise<fs.BigIntStats>;
/** 删除文件或文件夹，返回是否实际进行了删除操作
    - fp: 文件或文件夹的完整路径
    - options?:
        - print?: `true` */
export declare function fdelete(fp: string, { print }?: {
    print?: boolean;
    red?: boolean;
}): Promise<boolean>;
/** 清空文件夹中的内容，实际为删除该文件夹后新建 */
export declare function fdclear(fpd: string, { print, permission }?: {
    print?: boolean;
    permission?: boolean;
}): Promise<string>;
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<string>;
export interface FMoveOptions {
    overwrite?: boolean;
    print?: boolean;
}
/** 移动文件或文件夹
    相同分区 / 文件系统下使用 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<string>;
/** 重命名文件  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<void>;
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<string>;
/** 创建软链接
    - fp_real: 现在真实文件/文件夹的路径
    - fp_link: 目标链接文件/文件夹的路径
    - options?:
        - skip_existing?: `false` 忽略已存在的同名的文件，文件夹
        - print?: `true`
        - junction? */
export declare function flink(fp_real: string, fp_link: string, { skip_existing, print, junction }?: {
    skip_existing?: boolean;
    print?: boolean;
    junction?: boolean;
}): Promise<void>;
export interface UnzipOptions {
    encoding?: Encoding;
    dryrun?: boolean;
    print?: {
        info: boolean;
        files: boolean;
    };
    strip?: boolean;
    clean?: boolean;
    filter?: UnzipFileFilter;
}
/** 解压 zip 包至文件夹，返回 fpd_out
     - zip:
        - 包路径 (string) 或
        - 包数据 (Uint8Array | ArrayBuffer)
     - fpd_out: 解压到文件夹的完整路径 (string)
    - options?:
        - encoding?: `utf-8` 压缩包文件名编码
        - dryrun?: 只是打印一下文件名列表，看看编码是否正确，不实际解压
        - print?:
            - info?: `true` 开始解压、解压完成
            - files?: `true` 打印解压缩的文件列表
        - strip?: `true` 压缩包内只有一个顶层文件夹时自动去除该层级
        - clean?: `true` 忽略解压 ftrashes 这些垃圾文件
        - filter?: 用于过滤要解压的文件, 返回 falsy 值时忽略这个文件，要注意 file.name 为完整的相对路径（没有 strip） */
export declare function funzip(zip: string | Uint8Array | ArrayBuffer, fpd_out: string, options?: UnzipOptions): Promise<string>;
/** 解压 zip 包至内存，返回解压后的数据 (Record<文件或文件夹 (以 / 结尾) 的相对路径, Uint8Array>)
     - zip:
        - 压缩文件路径 (string) 或
        - 压缩文件内容 (buffer)
    - options?:
        - encoding?: `utf-8` 压缩包文件名编码
        - dryrun?: 只是打印一下文件名列表，看看编码是否正确，不实际解压
        - print?:
            - info?: `true` 开始解压、解压完成
            - files?: `true` 打印解压缩的文件列表
        - strip?: `true` 压缩包内只有一个顶层文件夹时自动去除该层级
        - clean?: `true` 忽略解压 ftrashes 这些垃圾文件
        - filter?: 用于过滤要解压的文件, 返回 falsy 值时忽略这个文件，要注意 file.name 为完整的相对路径（没有 strip） */
export declare function unzip(zip: string | Uint8Array | ArrayBuffer, options?: UnzipOptions): Promise<Record<string, Uint8Array>>;
export declare let fwatchers: Record<string, fs.FSWatcher>;
/** 跟踪文本文件追加的内容，类似 tail -f */
export declare function ftail(fp: string, handler: (lines: string[]) => void | Promise<void>, { print }?: {
    print?: boolean;
}): Promise<fs.FSWatcher>;
/** 打开一个文件并搜索替换某个 pattern */
export declare function freplace(fp: string, pattern: string | RegExp, replacement: string | ((substring: string, ...args: any[]) => string), { print }?: {
    print?: boolean;
}): Promise<void>;
interface FSyncOptions {
    print?: {
        info: boolean;
        files: boolean;
    };
    delete?: boolean;
}
/** 同步文件或文件夹 fp_src 到 fp_dst ，返回 fp_dst
    - fp_src: 源文件或文件夹
    - fp_dst: 目标文件或文件夹
    - options?:
        - print?: `print_info`
        - delete?: `false` */
export declare function fsync(fp_src: string, fp_dst: string, { print, delete: _delete }?: FSyncOptions): Promise<string>;
/** 根据对象的 fp 属性进行字典序排序 */
export declare function fp_sorter(l: {
    fp: string;
}, r: {
    fp: string;
}): 0 | 1 | -1;
export declare function log_action(action: string, fp_src: string, fp_dst: string, sep?: string): void;
