/* * Copyright (c) 2024 Huawei Device Co., Ltd. All rights reserved * Use of this source code is governed by a MIT license that can be * found in the LICENSE file. */ import type { TurboModule } from 'react-native'; import { TurboModuleRegistry } from 'react-native'; type MkdirOptionsT = { NSURLIsExcludedFromBackupKey?: boolean; }; type StatResult = { ctime: number; // The creation date of the file mtime: number; // The last modified date of the file size: number; // Size in bytes mode: number; // UNIX file mode originalFilepath: string; // In case of content uri this is the pointed file path, otherwise is the same as path type: number // Is the file just a file? // Is the file a directory? }; type DownloadResult = { jobId: number; // The download job ID, required if one wishes to cancel the download. See `stopDownload`. statusCode: number; // The HTTP status code bytesWritten: number; // The number of bytes written to the file }; type UploadResult = { jobId: number; // The upload job ID, required if one wishes to cancel the upload. See `stopUpload`. statusCode: number; // The HTTP status code body: string; // The HTTP response body headers?: Object; // The HTTP response headers from the server }; export interface Spec extends TurboModule { getConstants(): Object; readFile(path: string): Promise; exists(path: string): Promise; mkdir(path: string, options?: MkdirOptionsT): Promise; appendFile(path: string, contents: string, encoding?: string): Promise; writeFile(path: string, contents: string, encoding?: string): Promise; readFileAssets(path: string): Promise; copyFile(from: string, into: string): Promise; unlink(filepath: string): Promise; hash(filepath: string, algorithm: string): Promise; moveFile(filepath: string, destPath: string): Promise; read(path: string, length: number, position: number): Promise; write(filepath: string, contents: string, position: number): Promise; stat(filepath: string): Promise; touch(filepath: string, mtime?: number, ctime?: number): Promise; downloadFile(bridgeOptions: Object): Promise; uploadFiles(options: Object): Promise; readDir(dirpath: string): Promise; existsAssets(filepath: string):Promise; addListener(eventName: string): void; removeListeners(count: number): void; } export default TurboModuleRegistry.getEnforcing('ReactNativeFs');