import { NativeModules } from 'react-native' import { base64 } from 'rfc4648' import { normalizePath } from '../helpers/paths' import { Disklet, DiskletListing } from '../types' const native = NativeModules.Disklet /** * Returns a Disklet interface located in the application's data directory. */ export function makeReactNativeDisklet(): Disklet { return { delete(path: string): Promise { return native.delete(normalizePath(path)) }, getData(path: string): Promise { return native .getData(normalizePath(path)) .then((data: string) => base64.parse(data)) }, getText(path: string): Promise { return native.getText(normalizePath(path)) }, list(path: string = ''): Promise { return native.list(normalizePath(path)) }, setData(path: string, data: ArrayLike): Promise { return native.setData(normalizePath(path), base64.stringify(data)) }, setText(path: string, text: string): Promise { return native.setText(normalizePath(path), text) } } }