alpha0010 / react-native-file-access

Filesystem access for React Native
MIT License
308 stars 22 forks source link

Read file from assets directory #75

Open ShivamJoker opened 1 year ago

ShivamJoker commented 1 year ago

Feature Right now I am not sure how can I read file which is in android\app\src\main\assets

Motivation I have markdown file which I want to read and render.

alpha0010 commented 12 months ago

Here is an example of reading data from android assets: https://github.com/alpha0010/react-native-file-access/blob/v3.0.4/example/src/App.tsx#L31-L36 (targets this file).

ShivamJoker commented 12 months ago

Why do we need to copy the file every time I need to read it?

It would be great if we could directly read from the app res directory.

alpha0010 commented 11 months ago

Main reason is I never needed to read assets in my projects, so I did not spend time programming it. For my projects, assets have been binary files (e.g. databases, images) unpacked to a specific location for other native code to handle; not any content I needed to see from JS side.

I am open to suggestions on how to make this easier to use. A difficulty is I would prefer to avoid bloating API by adding a bunch of xxAsset() functions to mirror the plain file functions. Any thoughts on how to augment the existing API to support referencing assets whenever used as a readonly file?

ShivamJoker commented 11 months ago

If possible it would be best to add the assets in the directory constants itself. Eg. Dirs.Assets.

Then we will be able to use all the existing APIs and we can remove cpAssets as well if we want.