A React Native library making file access easier for developers as first class citizens, without the tears

Overview

React Native File Gateway

npm npm npm

A React Native library making file access easier for developers as first class citizens, without the tears.

⚠️ NOTE: This library is in early development, focusing primarily on Android. ⚠️

About

This library is focused around making the developer's life simpler when it comes to interacting with the native file system for React Native. This library has 3 main goals:

  • Being simple, and easy to understand
    • This may mean some things are abstracted/opinionated (see writeFile() as one example of this)
  • Being performant
    • Handling large/many files is a must. Any file interopability is always handled at the native level
  • Being well tested
    • Where tests are needed, they will be there. Native or at the JS level, a test will accompany said code

Supported platforms

  • Android (In development)

Upcoming platforms

  • iOS
  • Windows
  • MacOS

Roadmap

  • File system interoperability (In progress)
  • Downloading/uploading files
  • Cryptography
  • Unit/integration/E2E testing (TO:DO)

Installation

npm install react-native-file-gateway

Usage

import FileGateway from  "react-native-file-gateway";

// Scenario 1: Writing an MP4 file to the secure application store.
// This file will be deleted on uninstall.
const path = await FileGateway.writeFile(
  "bigBuckBunny.mp4", // Name of the file
  "010101", // Data to be written as a string (UTF-8 encoding is default)
  "application" // Intention of the file's lifetime. Can be application, ephemeral, or persistent (see more in documentation below)
)

// Scenario 2: Writing an image file to the cache.
// This file will be deleted on uninstall.
const path = await FileGateway.writeFile(
  "bigBuckBunny.mp4",
  "010101",
  "ephemeral" // Ephemeral will store this file into the system's cache
)

// Scenario 3: Writing an image file to the cache using base64 encoding.
const path = await FileGateway.writeFile(
  "bigBuckBunny.mp4",
  {
    data: "010101",
    encoding: "base64" // Specifying this will encode the written file as base64 (UTF-8 as the charset)
  },
  "ephemeral"
)

Functions

writeFile(fileName: string, data: string | DataWithEncoding, intention: Intention, collection?: Collection): Promise<string> - Writes to a file and returns it's path as a Promise<string>

  • DataWithEncoding - explicitly define the encoding ("utf-8", "utf-16", "utf-32", "base64") within the encoding key, and the data within the payload key
    • { data: string; encoding: Encoding }
  • Intention: Intention ("application" | "ephemeral" | "persistent")
    • The intention is to indicate how the file will be stored.
      • application intention will allocate the file into the application's own storage, but other applications won't be able to access it. The file will be lost on uninstall.
      • ephemeral intention will allocate the file into the cache storage. The file will be lost on uninstall
      • persistent intention will allocate the file into external storage. The file will persist on uninstall. Useful for media content.
  • Collection ("audio" | "image" | "video" | "download")
    • The collection is to indicate where the file will be stored (ONLY APPLICABLE FOR persistent intentions). Fallsback to download if not specified.

readFile(path: string, encoding?: Encoding): Promise<string> - Reads a given file, given it's path and returns the data as a Promise<string>

  • Encoding ("utf-8", "utf-16", "utf-32", "base64")
    • Sets the encoding when reading the file

deleteFile(path: string): Promise<string> - Deletes a file, given it's path and returns the path if successful as a Promise<string>


status(path: string): Promise<RawStatus> - Returns back the Promise<RawStatus> of a file, given it's path

  • RawStatus includes the following
    • size (in bytes)
    • mimeType (e.g application/javascript)
    • extension (e.g mp3)
    • nameWithoutExtension (e.g bigBuckBunny)
    • lastModified (e.g 2021-05-19T21:10:48.197Z- ISO UTC format)
    • creationTime (e.g 2021-05-19T21:10:48.197Z- ISO UTC format)
    • lastAccessedTime (e.g 2021-05-19T21:10:48.197Z- ISO UTC format)

listFiles(path: string, recursive?: boolean): Promise<string[]> - List all the files, given it's path and returns all the file names as a Promise<string[]>

  • Specifying recursive as true will recursively search through every directory for the given path

exists(path: string): Promise<boolean> - Checks if a file or directory exists. Returns true or false if a file exists, or doesn't, respectively as a Promise<boolean>


isDirectory(path: string): Promise<boolean> - Checks if the given path is a directory exists. Returns true or false if it's a directory, or not, respectively as a Promise<boolean>


moveDirectory(path: string, targetPath: string): Promise<string> - Moves a directory from the path to the targetPath (the destination). Any files at the destination will be overridden by default. Returns back the targetPath as a Promise<string>


deleteDirectory(path: string): Promise<string> - Deletes a directory, given it's path and returns the path if successful as a Promise<string>

Contributing

See the contributing guide to learn how to contribute to the repository and the development workflow.

License

MIT

You might also like...
This is a first kotlin project
This is a first kotlin project

SmallPocket This is a first kotlin app, help user to save links easily, and can export to Evernote as weekly. Steps: copy link anywhere open SmallPock

Shoe Store project first Attempt

Shoe Store project first Attempt User Info: email: [email protected] password:12345 I had problem to select the home Screen for the navigation gr

Minimal UI library for Android inspired by React
Minimal UI library for Android inspired by React

Anvil - reactive views for Android Anvil is a small Java library for creating reactive user interfaces. Originally inspired by React, it suits well as

A react-like kotlin library to create an inventory ui easily in paper plugins
A react-like kotlin library to create an inventory ui easily in paper plugins

A react-like kotlin library to create an inventory ui easily in paper plugins

Android utilities for easier and faster Kotlin programming.
Android utilities for easier and faster Kotlin programming.

Android utilities for easier and faster Kotlin programming. Download Gradle compile 'com.costular:kotlin-utils:0.1' How to use It depends on utilities

A collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android.

requireKTX requireKTX is a collection of small utility functions to make it easier to deal with some otherwise nullable APIs on Android, using the sam

A set of extension properties on Int, Long, Double, and Duration, that makes it easier to work with Kotlin Duration

Kotlin Duration Extensions Gradle Groovy repositories { mavenCentral() } implementation 'com.eygraber:kotlin-duration-extensions:1.0.1' Kotlin rep

Kotlin tooling for generating kotlinx.serialization serializers for serializing a class as a bitmask

kotlinx-serialization-bitmask Kotlin tooling for generating kotlinx.serialization serializers for serializing a class as a bitmask. Example @Serializa

Netflix inspired OTT Home Screen, Contains implementation in Reactjs, Kotlin React Wrapper, Jetpack Compose Web

Netflix-Clone-React Practising React by building Netflix Clone Requirements TMDB api key : Add TMDB API key to AppApi.kt Learning Resourcce Build Netf

Comments
  • feat(android): add different encoding methods

    feat(android): add different encoding methods

    Adds the different encoding methods (utf-8, utf-16, utf-32, base64) for reading and writing files

    base64 by default uses the utf-8 charset, if theres a need to separate this out in future to support different charsets then it may be considered

    released 
    opened by iJimmyWei 2
  • Improvement/android tests

    Improvement/android tests

    Adds the necessary android tests for majority of the methods exposed. Address #8

    • deleteDirectory is now exposed, returns the path if successful
    • deleteFile now returns the path if successful
    released 
    opened by iJimmyWei 1
  • feat(android): add a status() method

    feat(android): add a status() method

    Adds a status() method for android

    Returns back the following

    size: number;
    mimeType?: string;
    extension: string;
    nameWithoutExtension: string;
    lastModified: string;
    creationTime?: string; // API Level 26 and above only 
    lastAccessedTime?: string; // API Level 26 and above only
    

    Fixes #2

    released 
    opened by iJimmyWei 1
  • Feat/add write file method

    Feat/add write file method

    Implements a writeFile() method that supports scoped storage for the following collections: image, audio, video and download for any given persistent intentions

    Resolves #1

    opened by iJimmyWei 0
Releases(v1.5.1)
Owner
Jimmy Wei
Software Engineer
Jimmy Wei
It is far easier to design a class to be thread-safe than to retrofit it for thread safety later

"It is far easier to design a class to be thread-safe than to retrofit it for thread safety later." (Brian Goetz - Java concurrency: Publisher: Addiso

Nguyễn Trường Thịnh 3 Oct 26, 2022
DocuBox is a cloud based file storing app where you can securely store and access your documents from anywhere around the world

DocuBox is an android app ??in which you can securely upload your files on the cloud– from family pictures and audio recordings to spreadsheets, presentations and other confidential documents.

Vaibhav Jaiswal 26 Jan 3, 2023
[Android Library] Get easy access to device information super fast, real quick

DeviceInfo-Sample Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the d

Anitaa Murthy 193 Nov 20, 2022
This library is a set of simple wrapper classes that are aimed to help you easily access android device information.

SysInfo Simple, single class wrapper to get device information from an android device. This library provides an easy way to access all the device info

Klejvi Kapaj 7 Dec 27, 2022
Android Library to make SharedPreferences usage easier.

KotlinPreferences Kotlin Android Library, that makes preference usage simple and fun. KotlinPreferences now have a brother. With KotlinPreferences, yo

Marcin Moskała 50 Nov 6, 2022
Stateful is a Kotlin library which makes Android application development faster and easier.

Stateful Stateful is a Kotlin library which makes Android application development faster and easier. It helps you delete all the boilerplate code for

PicsArt 67 Oct 3, 2022
A fragment binding library - the easier, efficient way.

Byda allprojects { repositories { ... maven { url 'https://jitpack.io' } } } dependencies { implementation 'com.github.Codzure:B

null 3 May 27, 2021
Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier.

Kstr is a set of helpful methods library for Kotlin intended for make the developer life easier. Kstr uses the powerful feature of extension func

Rafael Acioly 0 Nov 3, 2021
Elixir is a library designed to make minecraft login easier.

Elixir Elixir is a library designed to make minecraft login easier. Usage We have a maven repo for this project. repositories { maven { url = "htt

null 4 Aug 11, 2022
The Klutter CLI tool gives access to all tasks to create and manage a Klutter project.

Klutter CLI The Klutter CLI tool gives access to all tasks to create and manage a Klutter project. Gettings started Download the tool. Unzip the file.

Gillian 2 Mar 31, 2022