react-native-fs-turbo
Version:
React-Native library for working with Android/iOS file system, written using JSI and C++ TurboModules
50 lines (44 loc) • 1.85 kB
JavaScript
import { TurboModuleRegistry } from "react-native";
import { ModuleNotFoundError } from "./ModuleNotFoundError";
import { getRNFSTurboPlatformContextTurboModule } from "./NativeRNFSTurboPlatformContextModule";
/**
* Used for configuration of a single RNFSTurbo instance.
*/
/**
* Used for configuration of a single RNFSTurbo instance.
*/
let module;
let configuration;
export function getRNFSTurboModule() {
try {
if (module == null) {
// 1. Load RNFS TurboModule
module = TurboModuleRegistry.getEnforcing("RNFSTurboModule");
// 2. Get the PlatformContext TurboModule as well
const platformContext = getRNFSTurboPlatformContextTurboModule();
// 3. Initialize it with the storage directores from platform-specific context
configuration = {
mainBundlePath: platformContext.getMainBundlePath(),
cachesDirectoryPath: platformContext.getCachesDirectoryPath(),
documentDirectoryPath: platformContext.getDocumentDirectoryPath(),
temporaryDirectoryPath: platformContext.getTemporaryDirectoryPath(),
libraryDirectoryPath: platformContext.getLibraryDirectoryPath(),
externalDirectoryPath: platformContext.getExternalDirectoryPath(),
externalStorageDirectoryPath: platformContext.getExternalStorageDirectoryPath(),
externalCachesDirectoryPath: platformContext.getExternalCachesDirectoryPath(),
downloadDirectoryPath: platformContext.getDownloadDirectoryPath(),
picturesDirectoryPath: platformContext.getPicturesDirectoryPath(),
roamingDirectoryPath: platformContext.getRoamingDirectoryPath()
};
}
return {
configuration,
module
};
} catch {
// TurboModule could not be found!
throw new ModuleNotFoundError();
}
}
//# sourceMappingURL=NativeRNFSTurboModule.js.map
;