UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

61 lines (60 loc) 1.99 kB
/** * 写入文件 * @param {string} file 文件地址 * @param {any} data 文件数据 * @param {boolean} [isJson] 是否需要 json 序列化 * @example * ```ts * writeFileSync('a', 'b.txt', false); * * writeFileSync({ a: 1 }, 'b.json', true); * ``` */ export declare function writeFileSync(file: string, data: any, isJson?: boolean): void; /** * 读取文件 * @param {string} file 文件地址 * @param {boolean} [isJson] 是否需要 json 反序列化 * @returns {any} 文件内容 * @example * ```ts * readFileSync('b.txt', false); * * readFileSync('b.json', true); * ``` */ export declare function readFileSync(file: string, isJson?: boolean): any; export declare function isDirectory(filePath?: string): boolean; export declare function ensureDir(dir: string): void; /** * 计算本地文件的哈希值 * @param {string} filePath 文件路径 * @param {'md5' | 'sha1' | 'sha256'} [algorithm='md5'] 哈希算法 * @returns {string | null} 哈希值(hex 字符串);文件不存在或读取失败时返回 null * @example * ```ts * const md5 = getLocalFileHash('/path/to/file'); * const sha256 = getLocalFileHash('/path/to/file', 'sha256'); * ``` */ export declare function getLocalFileHash(filePath: string, algorithm?: 'md5' | 'sha1' | 'sha256'): string | null; /** * 计算本地文件的 MD5 * @param {string} filePath 文件路径 * @returns {string | null} MD5 值(hex 字符串);文件不存在或读取失败时返回 null * @example * ```ts * const md5 = getLocalFileMd5('/path/to/file'); * ``` */ export declare function getLocalFileMd5(filePath: string): string | null; /** * 获取本地文件大小(字节数) * @param {string} filePath 文件路径 * @returns {number | null} 文件大小(字节);文件不存在或读取失败时返回 null * @example * ```ts * const size = getLocalFileSize('/path/to/file'); * ``` */ export declare function getLocalFileSize(filePath: string): number | null;