Skip to content

Commit 75ade0b

Browse files
authored
Merge pull request #56 from robwalkerco/refactor/use-react-native-blob-util
Use react-native-blob-util ^0.13.12
2 parents f21e0e6 + 22514a2 commit 75ade0b

File tree

4 files changed

+27
-32
lines changed

4 files changed

+27
-32
lines changed

README.md

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
[![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)
44
[![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)
55

6-
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`.
6+
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`.
77

88
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))
99

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

24-
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
24+
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).
2525

26-
```
27-
react-native link rn-fetch-blob
28-
```
29-
30-
(or check [their docs](https://github.com/joltup/rn-fetch-blob#user-content-installation)).
3126

3227
## usage
3328

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22
* @flow
33
*/
44

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

77
const createStoragePathIfNeeded = path =>
8-
RNFetchBlob.fs
8+
ReactNativeBlobUtil.fs
99
.exists(path)
1010
.then(exists =>
1111
exists
1212
? new Promise(resolve => resolve(true))
13-
: RNFetchBlob.fs.mkdir(path)
13+
: ReactNativeBlobUtil.fs.mkdir(path)
1414
);
1515

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

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

2424
let onStorageReady = onStorageReadyFactory(defaultStoragePath);
2525
let options = {
@@ -42,7 +42,7 @@ const FilesystemStorage = {
4242
},
4343

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

54-
return RNFetchBlob.fs
54+
return ReactNativeBlobUtil.fs
5555
.readFile(filePath, options.encoding)
5656
.then(data => {
5757
if (!callback) {
@@ -60,7 +60,7 @@ const FilesystemStorage = {
6060
callback(null, data);
6161
})
6262
.catch(err => {
63-
return RNFetchBlob.fs
63+
return ReactNativeBlobUtil.fs
6464
.exists(filePath)
6565
.then(exists => {
6666
if (!exists) {
@@ -86,13 +86,13 @@ const FilesystemStorage = {
8686
callback(err);
8787
}
8888

89-
return RNFetchBlob.fs
89+
return ReactNativeBlobUtil.fs
9090
.exists(filePath)
9191
.then(exists => {
9292
if (!exists) {
9393
return null;
9494
} else {
95-
return RNFetchBlob.fs
95+
return ReactNativeBlobUtil.fs
9696
.unlink(filePath)
9797
.then(() => callback && callback())
9898
.catch(handleError);
@@ -102,13 +102,13 @@ const FilesystemStorage = {
102102
},
103103

104104
getAllKeys: (callback?: (error: ?Error, keys: ?Array<string>) => any) =>
105-
RNFetchBlob.fs
105+
ReactNativeBlobUtil.fs
106106
.exists(options.storagePath)
107107
.then(exists =>
108-
exists ? true : RNFetchBlob.fs.mkdir(options.storagePath)
108+
exists ? true : ReactNativeBlobUtil.fs.mkdir(options.storagePath)
109109
)
110110
.then(() =>
111-
RNFetchBlob.fs
111+
ReactNativeBlobUtil.fs
112112
.ls(options.storagePath)
113113
.then(files => files.map<string>(file => options.fromFileName(file)))
114114
.then(files => {

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "redux-persist-filesystem-storage",
3-
"version": "3.0.0",
3+
"version": "4.0.0",
44
"description": "Redux persist adaptor for React Native filesystem storage",
55
"main": "index.js",
66
"repository": {
@@ -13,7 +13,7 @@
1313
"flow": "flow"
1414
},
1515
"dependencies": {
16-
"rn-fetch-blob": "^0.12.0"
16+
"react-native-blob-util": "^0.13.12"
1717
},
1818
"devDependencies": {
1919
"flow-bin": "^0.108.0"

yarn.lock

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ fs.realpath@^1.0.0:
3535
resolved "https://registry.yarnpkg.com/fs.realpath/-/fs.realpath-1.0.0.tgz#1504ad2523158caa40db4a2787cb01411994ea4f"
3636
integrity sha1-FQStJSMVjKpA20onh8sBQRmU6k8=
3737

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

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

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

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

9090
wrappy@1:
9191
version "1.0.2"

0 commit comments

Comments
 (0)