Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #56 from robwalkerco/refactor/use-react-native-blo…
…b-util

Use react-native-blob-util ^0.13.12
  • Loading branch information
robwalkerco committed Aug 26, 2021
2 parents f21e0e6 + 22514a2 commit 75ade0b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 32 deletions.
9 changes: 2 additions & 7 deletions README.md
Expand Up @@ -3,7 +3,7 @@
[![npm version](https://img.shields.io/npm/v/redux-persist-filesystem-storage.svg?style=flat-square)](https://www.npmjs.com/package/redux-persist-filesystem-storage)
[![npm downloads](https://img.shields.io/npm/dt/redux-persist-filesystem-storage.svg?style=flat-square)](https://www.npmjs.com/package/redux-persist-filesystem-storage)

Storage adaptor to use [react-native-fetch-blob](https://github.com/wkh237/react-native-fetch-blob) with [redux-persist](https://github.com/rt2zz/redux-persist), by implementing the needed methods: `setItem`, `getItem`, `removeItem`, `getAllKeys` and `clear`.
Storage adaptor to use [react-native-blob-util](https://github.com/RonRadtke/react-native-blob-util) with [redux-persist](https://github.com/rt2zz/redux-persist), by implementing the needed methods: `setItem`, `getItem`, `removeItem`, `getAllKeys` and `clear`.

This storage can be used on Android to prevent issues with the storage limitations in the RN AsyncStorage implementation. (See [redux-persist#199](https://github.com/rt2zz/redux-persist/issues/199), [redux-persist#284](https://github.com/rt2zz/redux-persist/issues/284))

Expand All @@ -21,13 +21,8 @@ or, for React Native 0.59 and below:
yarn add redux-persist-filesystem-storage@1
```

Then, as [rn-fetch-blob](https://github.com/joltup/rn-fetch-blob) is a dependency of this project, we need to ensure its linked with
Then, as [react-native-blob-util](https://github.com/RonRadtke/react-native-blob-util) is a dependency of this project, it will also need setting up as its [their installation docs](https://github.com/RonRadtke/react-native-blob-util#installation).

```
react-native link rn-fetch-blob
```

(or check [their docs](https://github.com/joltup/rn-fetch-blob#user-content-installation)).

## usage

Expand Down
24 changes: 12 additions & 12 deletions index.js
Expand Up @@ -2,15 +2,15 @@
* @flow
*/

import RNFetchBlob from "rn-fetch-blob";
import ReactNativeBlobUtil from 'react-native-blob-util';

const createStoragePathIfNeeded = path =>
RNFetchBlob.fs
ReactNativeBlobUtil.fs
.exists(path)
.then(exists =>
exists
? new Promise(resolve => resolve(true))
: RNFetchBlob.fs.mkdir(path)
: ReactNativeBlobUtil.fs.mkdir(path)
);

const onStorageReadyFactory = (storagePath: string) => (func: Function) => {
Expand All @@ -19,7 +19,7 @@ const onStorageReadyFactory = (storagePath: string) => (func: Function) => {
return (...args: Array<any>) => storage.then(() => func(...args));
};

const defaultStoragePath = `${RNFetchBlob.fs.dirs.DocumentDir}/persistStore`;
const defaultStoragePath = `${ReactNativeBlobUtil.fs.dirs.DocumentDir}/persistStore`;

let onStorageReady = onStorageReadyFactory(defaultStoragePath);
let options = {
Expand All @@ -42,7 +42,7 @@ const FilesystemStorage = {
},

setItem: (key: string, value: string, callback?: (error: ?Error) => void) =>
RNFetchBlob.fs
ReactNativeBlobUtil.fs
.writeFile(pathForKey(key), value, options.encoding)
.then(() => callback && callback())
.catch(error => callback && callback(error)),
Expand All @@ -51,7 +51,7 @@ const FilesystemStorage = {
(key: string, callback?: (error: ?Error, result: ?(Array<number> | string)) => void) => {
const filePath = pathForKey(options.toFileName(key));

return RNFetchBlob.fs
return ReactNativeBlobUtil.fs
.readFile(filePath, options.encoding)
.then(data => {
if (!callback) {
Expand All @@ -60,7 +60,7 @@ const FilesystemStorage = {
callback(null, data);
})
.catch(err => {
return RNFetchBlob.fs
return ReactNativeBlobUtil.fs
.exists(filePath)
.then(exists => {
if (!exists) {
Expand All @@ -86,13 +86,13 @@ const FilesystemStorage = {
callback(err);
}

return RNFetchBlob.fs
return ReactNativeBlobUtil.fs
.exists(filePath)
.then(exists => {
if (!exists) {
return null;
} else {
return RNFetchBlob.fs
return ReactNativeBlobUtil.fs
.unlink(filePath)
.then(() => callback && callback())
.catch(handleError);
Expand All @@ -102,13 +102,13 @@ const FilesystemStorage = {
},

getAllKeys: (callback?: (error: ?Error, keys: ?Array<string>) => any) =>
RNFetchBlob.fs
ReactNativeBlobUtil.fs
.exists(options.storagePath)
.then(exists =>
exists ? true : RNFetchBlob.fs.mkdir(options.storagePath)
exists ? true : ReactNativeBlobUtil.fs.mkdir(options.storagePath)
)
.then(() =>
RNFetchBlob.fs
ReactNativeBlobUtil.fs
.ls(options.storagePath)
.then(files => files.map<string>(file => options.fromFileName(file)))
.then(files => {
Expand Down
4 changes: 2 additions & 2 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "redux-persist-filesystem-storage",
"version": "3.0.0",
"version": "4.0.0",
"description": "Redux persist adaptor for React Native filesystem storage",
"main": "index.js",
"repository": {
Expand All @@ -13,7 +13,7 @@
"flow": "flow"
},
"dependencies": {
"rn-fetch-blob": "^0.12.0"
"react-native-blob-util": "^0.13.12"
},
"devDependencies": {
"flow-bin": "^0.108.0"
Expand Down
22 changes: 11 additions & 11 deletions yarn.lock
Expand Up @@ -35,15 +35,15 @@ fs.realpath@^1.0.0:
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=

glob@7.0.6:
version "7.0.6"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.0.6.tgz#211bafaf49e525b8cd93260d14ab136152b3f57a"
integrity sha1-IRuvr0nlJbjNkyYNFKsTYVKz9Xo=
glob@^7.1.6:
version "7.1.7"
resolved "https://registry.yarnpkg.com/glob/-/glob-7.1.7.tgz#3b193e9233f01d42d0b3f78294bbeeb418f94a90"
integrity sha512-OvD9ENzPLbegENnYP5UUfJIirTg4+XwMWGaQfQTY0JenxNvvIKP3U3/tAQSPIu/lHxXYSZmpXlUHeqAIdKzBLQ==
dependencies:
fs.realpath "^1.0.0"
inflight "^1.0.4"
inherits "2"
minimatch "^3.0.2"
minimatch "^3.0.4"
once "^1.3.0"
path-is-absolute "^1.0.0"

Expand All @@ -60,7 +60,7 @@ inherits@2:
resolved "https://registry.yarnpkg.com/inherits/-/inherits-2.0.4.tgz#0fa2c64f932917c3433a0ded55363aae37416b7c"
integrity sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==

minimatch@^3.0.2:
minimatch@^3.0.4:
version "3.0.4"
resolved "https://registry.yarnpkg.com/minimatch/-/minimatch-3.0.4.tgz#5166e286457f03306064be5497e8dbb0c3d32083"
integrity sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==
Expand All @@ -79,13 +79,13 @@ path-is-absolute@^1.0.0:
resolved "https://registry.yarnpkg.com/path-is-absolute/-/path-is-absolute-1.0.1.tgz#174b9268735534ffbc7ace6bf53a5a9e1b5c5f5f"
integrity sha1-F0uSaHNVNP+8es5r9TpanhtcX18=

rn-fetch-blob@^0.12.0:
version "0.12.0"
resolved "https://registry.yarnpkg.com/rn-fetch-blob/-/rn-fetch-blob-0.12.0.tgz#ec610d2f9b3f1065556b58ab9c106eeb256f3cba"
integrity sha512-+QnR7AsJ14zqpVVUbzbtAjq0iI8c9tCg49tIoKO2ezjzRunN7YL6zFSFSWZm6d+mE/l9r+OeDM3jmb2tBb2WbA==
react-native-blob-util@^0.13.12:
version "0.13.12"
resolved "https://registry.yarnpkg.com/react-native-blob-util/-/react-native-blob-util-0.13.12.tgz#7fa8924eefb6a7440cbb1a79bd213c8c29db3673"
integrity sha512-dW3ArdArcKY1066u4KV5x7bl+qgIwLmLPXppeonMwhzhi0o5H6A2r2rflLeZeYI3FC66Ot/hp0TOqo9FEv7I4w==
dependencies:
base-64 "0.1.0"
glob "7.0.6"
glob "^7.1.6"

wrappy@1:
version "1.0.2"
Expand Down

0 comments on commit 75ade0b

Please sign in to comment.