react-native-fs-turbo
Version:
React-Native library for working with Android/iOS file system, written using JSI and C++ TurboModules
207 lines • 8.15 kB
TypeScript
export type StatResult<S> = {
path: string;
ctime: Date;
mtime: Date;
size: number;
mode: number;
originalFilepath: string;
isFile: S;
isDirectory: S;
};
export type ReadDirItem<S> = {
ctime: Date;
mtime: Date;
name: string;
path: string;
size: string;
isFile: S;
isDirectory: S;
};
export type DownloadFileOptions = {
fromUrl: string;
toFile: string;
headers?: {
[key: string]: string | number;
};
background?: boolean;
discretionary?: boolean;
cacheable?: boolean;
progressInterval?: number;
progressDivider?: number;
begin?: (res: DownloadBeginCallbackResult) => void;
progress?: (res: DownloadProgressCallbackResult) => void;
resumable?: () => void;
connectionTimeout?: number;
readTimeout?: number;
backgroundTimeout?: number;
};
export type DownloadResult = {
jobId: number;
statusCode: number;
bytesWritten: number;
};
export type DownloadError = {
jobId: number;
errorMessage: string;
};
export type DownloadBeginCallbackResult = {
jobId: number;
statusCode: number;
contentLength: number;
headers: {
[key: string]: string | number;
};
};
export type DownloadProgressCallbackResult = {
jobId: number;
contentLength: number;
bytesWritten: number;
};
export type UploadFileOptions = {
toUrl: string;
binaryStreamOnly?: boolean;
files: UploadFileItem[];
headers?: {
[key: string]: string | number;
};
fields?: {
[key: string]: string | number;
};
method?: string;
begin?: (res: UploadBeginCallbackResult) => void;
progress?: (res: UploadProgressCallbackResult) => void;
};
export type UploadFileItem = {
name: string;
filename: string;
filepath: string;
filetype: string;
};
export type UploadResult = {
jobId: number;
statusCode: number;
headers: {
[key: string]: string | number;
};
body: string;
};
export type UploadError = {
jobId: number;
errorMessage: string;
};
export type UploadBeginCallbackResult = {
jobId: number;
};
export type UploadProgressCallbackResult = {
jobId: number;
totalBytesExpectedToSend: number;
totalBytesSent: number;
};
export type FSInfoResult = {
totalSpace: number;
freeSpace: number;
totalSpaceEx?: number;
freeSpaceEx?: number;
};
export type ScanResult = {
jobId: number;
path: string;
};
export type ScanError = {
jobId: number;
errorMessage: string;
};
export type Algorithms = "md5" | "sha1" | "sha224" | "sha256" | "sha384" | "sha512";
export type DownloadResultFunc = ((res: DownloadResult) => void) | undefined;
export type DownloadErrorFunc = ((res: DownloadError) => void) | undefined;
export type UploadResultFunc = ((res: UploadResult) => void) | undefined;
export type UploadErrorFunc = ((res: UploadError) => void) | undefined;
export type ScanResultFunc = ((res: ScanResult) => void) | undefined;
export type OverloadedStatResult<T extends boolean | undefined> = T extends false | undefined ? StatResult<() => boolean> : StatResult<boolean>;
export type OverloadedReadDirItem<T extends boolean | undefined> = T extends false | undefined ? ReadDirItem<() => boolean> : ReadDirItem<boolean>;
export type OverloadedReadResult<T extends ReadOptions> = T extends "uint8" | "float32" ? number[] : string;
export type OverloadedDownloadResult<T extends DownloadResultFunc> = T extends undefined ? {
jobId: number;
promise: Promise<DownloadResult>;
} : {
jobId: number;
};
export type OverloadedUploadResult<T extends UploadResultFunc> = T extends undefined ? {
jobId: number;
promise: Promise<UploadResult>;
} : {
jobId: number;
};
export type OverloadedScanResult<T extends ScanResultFunc> = T extends undefined ? Promise<ScanResult> : {
jobId: number;
};
export type EncodingType = "utf8" | "base64" | "uint8" | "float32" | "ascii";
export type IOSProtectionTypes = "NSFileProtectionNone" | "NSFileProtectionComplete" | "NSFileProtectionCompleteUnlessOpen" | "NSFileProtectionCompleteUntilFirstUserAuthentication" | "NSFileProtectionCompleteWhenUserInactive";
export type ReadOptions = EncodingType | {
encoding: EncodingType;
} | undefined;
export type WriteOptions = EncodingType | {
encoding?: EncodingType;
NSFileProtectionKey?: IOSProtectionTypes;
} | undefined;
export type MoveCopyOptions = {
NSFileProtectionKey?: IOSProtectionTypes;
NSURLIsExcludedFromBackupKey?: boolean;
} | undefined;
export type MkdirOptions = {
NSFileProtectionKey?: IOSProtectionTypes;
NSURLIsExcludedFromBackupKey?: boolean;
} | undefined;
/**
* Represents a single RNFSTurbo instance.
*/
export interface RNFSTurboInterface {
readonly MainBundlePath: string;
readonly CachesDirectoryPath: string;
readonly DocumentDirectoryPath: string;
readonly TemporaryDirectoryPath: string;
readonly LibraryDirectoryPath: string;
readonly ExternalDirectoryPath: string;
readonly ExternalStorageDirectoryPath: string;
readonly ExternalCachesDirectoryPath: string;
readonly DownloadDirectoryPath: string;
readonly PicturesDirectoryPath: string;
readonly RoamingDirectoryPath: string;
stat<T extends boolean | undefined = false>(filepath: string, isNewFormat?: T): OverloadedStatResult<T>;
readDir<T extends boolean | undefined = false>(dirpath: string, isNewFormat?: T): OverloadedReadDirItem<T>[];
readDirAssets<T extends boolean | undefined = false>(dirpath: string, isNewFormat?: T): OverloadedReadDirItem<T>[];
readdir(dirpath: string): string[];
readFile<T extends ReadOptions = undefined>(filepath: string, options?: T): OverloadedReadResult<T>;
read<T extends ReadOptions = undefined>(filepath: string, length: number, position: number, options?: T): OverloadedReadResult<T>;
readFileAssets(filepath: string, options?: ReadOptions): string[];
readFileRes(filepath: string, options?: ReadOptions): string[];
writeFile(filepath: string, contents: string | number[], options?: WriteOptions): void;
appendFile(filepath: string, contents: string | number[], options?: WriteOptions): void;
write(filepath: string, contents: string | number[], position?: number, options?: WriteOptions): void;
moveFile(filepath: string, destPath: string, options?: MoveCopyOptions): void;
copyFolder(srcFolderPath: string, destFolderPath: string, options?: MoveCopyOptions): void;
copyFile(filepath: string, destPath: string, options?: MoveCopyOptions): void;
copyFileAssets(filepath: string, destPath: string): void;
copyFileRes(filepath: string, destPath: string): void;
copyAssetsFileIOS(imageUri: string, destPath: string, width: number, height: number, scale?: number, compression?: number, resizeMode?: string): string | undefined;
copyAssetsVideoIOS(videoUri: string, destPath: string): string | undefined;
unlink(filepath: string, checkExistence?: boolean): void;
exists(filepath: string): boolean;
existsAssets(filepath: string): boolean;
existsRes(filepath: string): boolean;
hash(filepath: string, algorithm: Algorithms): string;
touch(filepath: string, mtime?: Date | number, ctime?: Date | number): number;
mkdir(filepath: string, options?: MkdirOptions): void;
downloadFile<T extends DownloadResultFunc | undefined = undefined>(options: DownloadFileOptions, completeCallback?: T, errorCallback?: DownloadErrorFunc): OverloadedDownloadResult<T>;
stopDownload(jobId: number): void;
resumeDownload(jobId: number): void;
isResumable(jobId: number): boolean;
completeHandlerIOS(jobId: number): void;
uploadFiles<T extends UploadResultFunc = undefined>(options: UploadFileOptions, completeCallback?: T, errorCallback?: UploadErrorFunc): OverloadedUploadResult<T>;
stopUpload(jobId: number): void;
getFSInfo(): FSInfoResult;
scanFile<T extends ScanResultFunc = undefined>(path: string, completeCallback?: T): OverloadedScanResult<T>;
getAllExternalFilesDirs(): string[];
pathForGroup(groupIdentifier: string): string;
}
//# sourceMappingURL=Types.d.ts.map