tauri-plugin-fs-pro-api
Version:
Extended with additional methods for files and directories.
310 lines (309 loc) • 7.95 kB
TypeScript
export interface IconOptions {
/**
* The size of the icon, defaults to `32`.
*/
size?: number;
/**
* The path to save the icon, defaults to the default save path.
*/
savePath?: string;
}
export interface MetadataOptions {
/**
* When getting the metadata of a path, if you don't need to calculate the size, you can omit it to save time and return 0 after omitting it.
*/
omitSize?: boolean;
}
export interface Metadata {
/**
* The size of the path in bytes.
*/
size: number;
/**
* The file or directory name of the path.
*/
name: string;
/**
* The extension name of the path.
*/
extname: string;
/**
* The full name of the path including extension.
*/
fullName: string;
/**
* The parent directory name of the path.
*/
parentName: string;
/**
* Whether the path exists.
*/
isExist: boolean;
/**
* Whether the path is a file.
*/
isFile: boolean;
/**
* Whether the path is a directory.
*/
isDir: boolean;
/**
* Whether the path is a symbolic link.
*/
isSymlink: boolean;
/**
* Whether the path is an absolute path.
*/
isAbsolute: boolean;
/**
* Whether the path is a relative path.
*/
isRelative: boolean;
/**
* The access time of the path in milliseconds.
*/
accessedAt: number;
/**
* The creation time of the path in milliseconds.
*/
createdAt: number;
/**
* The modified time of the path in milliseconds.
*/
modifiedAt: number;
}
export interface CompressOptions {
/**
* The name of the file or directory to be compressed.
*/
includes?: string[];
/**
* The name of the file or directory not to be compressed.
*/
excludes?: string[];
}
export interface TransferOptions {
/**
* The name of the file or directory to be moved.
*/
includes?: string[];
/**
* The name of the file or directory not to be moved.
*/
excludes?: string[];
}
export declare const COMMAND: {
IS_EXIST: string;
IS_FILE: string;
IS_DIR: string;
SIZE: string;
NAME: string;
EXTNAME: string;
FULL_NAME: string;
PARENT_NAME: string;
GET_DEFAULT_SAVE_ICON_PATH: string;
ICON: string;
METADATA: string;
COMPRESS: string;
DECOMPRESS: string;
TRANSFER: string;
};
/**
* Check if a path exists.
*
* @param path Specify the path.
*
* @example
* ```
* import { isExist } from "tauri-plugin-fs-pro-api"
*
* const exists = await isExist("/path/to/file.txt")
* console.log(exists) // true
* ```
*/
export declare const isExist: (path: string) => Promise<boolean>;
/**
* Check if a path is a file.
*
* @param path Specify the path.
*
* @example
* ```
* import { isFile } from "tauri-plugin-fs-pro-api"
*
* const isFile = await isFile("/path/to/file.txt")
* console.log(isFile) // true
* ```
*/
export declare const isFile: (path: string) => Promise<boolean>;
/**
* Check if a path is a directory.
*
* @param path Specify the path.
*
* @example
* ```
* import { isDir } from "tauri-plugin-fs-pro-api"
*
* const isDir = await isDir("/path/to/dir")
* console.log(isDir) // true
* ```
*/
export declare const isDir: (path: string) => Promise<boolean>;
/**
* Get the size of the path, or 0 if it does not exist.
*
* @param path Specify the path.
*
* @example
* ```
* import { size } from "tauri-plugin-fs-pro-api"
*
* const size = await size("/path/to/file.txt")
* console.log(size) // 1024
* ```
*/
export declare const size: (path: string) => Promise<number>;
/**
* Get the name of the path.
*
* @param path Specify the path.
*
* @example
* ```
* import { name } from "tauri-plugin-fs-pro-api"
*
* const name = await name("/path/to/file.txt")
* console.log(name) // file
* ```
*/
export declare const name: (path: string) => Promise<string>;
/**
* Get the extension name of the path.
*
* @param path Specify the path.
*
* @example
* ```
* import { extname } from "tauri-plugin-fs-pro-api"
*
* const extname = await extname("/path/to/file.txt")
* console.log(extname) // txt
* ```
*/
export declare const extname: (path: string) => Promise<string>;
/**
* Get the full name of a file or directory including extension.
*
* @param path Specify the path.
*
* @example
* ```
* import { fullName } from "tauri-plugin-fs-pro-api"
*
* const fullName = await fullName("/path/to/file.txt")
* console.log(fullName) // file.txt
* ```
*/
export declare const fullName: (path: string) => Promise<string>;
/**
* Get the parent name of the path.
*
* @param path Specify the path.
* @param level Specify the level of the parent directory, defaults to `1`.
*
* @example
* ```
* import { parentName } from "tauri-plugin-fs-pro-api"
*
* const parentName = await parentName("/path/to/file.txt")
* console.log(parentName) // to
* ```
*/
export declare const parentName: (path: string, level?: number) => Promise<string>;
/**
* Get the default save icon path.
*
* @example
* ```
* import { getDefaultSaveIconPath } from "tauri-plugin-fs-pro-api"
*
* const savePath = await getDefaultSaveIconPath()
* console.log(savePath)
* ```
*/
export declare const getDefaultSaveIconPath: () => Promise<string>;
/**
* Get the icon of the path.
*
* @param path Specify the path.
* @param options.size Specify the size of the icon, defaults to `32`.
* @param options.savePath Specify the path to save the icon, defaults to the default save path.
*
* @example
* ```
* import { icon } from "tauri-plugin-fs-pro-api"
*
* const iconPath = await icon("/path/to/file.txt")
* console.log(iconPath)
* ```
*/
export declare const icon: (path: string, options: IconOptions) => Promise<string>;
/**
* Get the metadata of the path.
*
* @param path Specify the path.
* @param options.omitSize When getting the metadata of a path, if you don't need to calculate the size, you can omit it to save time and return 0 after omitting it,
* defaults to `false`.
*
* @example
* ```
* import { metadata } from "tauri-plugin-fs-pro-api"
*
* const metadata = await metadata("/path/to/file.txt")
* console.log(metadata)
* ```
*/
export declare const metadata: (path: string, options?: MetadataOptions) => Promise<Metadata>;
/**
* Compress the source path into a tar.gz file to the destination path.
*
* @param srcPath Specify the source path.
* @param dstPath Specify the destination path.
* @param options.includes The name of the file or directory to be compressed.
* @param options.excludes The name of the file or directory not to be compressed.
*
* @example
* ```
* import { compress } from "tauri-plugin-fs-pro-api"
*
* await compress("/path/to/source.txt", "/path/to/destination.tar.gz")
* ```
*/
export declare const compress: (srcPath: string, dstPath: string, options?: CompressOptions) => Promise<unknown>;
/**
* Decompress the tar.gz file from the source path to the destination path.
*
* @param srcPath Specify the source path.
* @param dstPath Specify the destination path.
*
* @example
* import { decompress } from "tauri-plugin-fs-pro-api"
*
* await decompress("/path/to/destination.tar.gz", "/path/to/source")
*/
export declare const decompress: (srcPath: string, dstPath: string) => Promise<unknown>;
/**
* Move the source path to the destination path.
*
* @param srcPath Specify the source path.
* @param dstPath Specify the destination path.
* @param options.includes The name of the file or directory to be moved.
* @param options.excludes The name of the file or directory not to be moved.
*b
* @example
* import { transfer } from "tauri-plugin-fs-pro-api"
*
* await transfer("/path/to/source", "/path/to/destination")
*/
export declare const transfer: (srcPath: string, dstPath: string, options?: TransferOptions) => Promise<unknown>;