You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* fs.js: forgot one more error refactoring
* Fix path argument in iOS excludeFromBackupKey (joltup#473)
* Fix link to fs.readStream() and to fs.writeStream() and insert link to new function fs.hash()
* Fix the documentation part of wkh237#467 "Example code for writeStream ignores that stream.write() returns a promise?"
* More fixes for issue wkh237#460 "Error normalization"
IMPORTANT: I wrote the iOS code BLIND (not even syntax highlighting) - this needs to be tested.
- Two or three methods that used callbacks to return results were changed to RN promises
- All methods using promises now use a Unix like code string for the first parameter, e.g. "ENOENT" for "File does not exist" (http://www.alorelang.org/doc/errno.html). The React Native bridge code itself uses this schema: it inserts "EUNSPECIFIED" when the "code" it gets back from Android/iOS code is undefined (null, nil). The RN bridge assigns the code (or "EUNSPECIFIED") to the "code" property of the error object it returns to Javascript, following the node.js example (the "code" property is not part of "standard" Javascript Error objects)
- Important errors like "No such file" are reported (instead of a general error), using the code property.
- I added a few extra error checks that the IDE suggested, mostly for Android (for which I have an IDE), if it seemed important I tried to do the same for teh iOS equivalent function
- I followed IDE suggestions on some of the Java code, like making fields private
- RNFetchBlobFS.java removeSession(): Added reporting of all failures to delete - IS THIS DESIRABLE (or do we not care)?
- readStream: The same schema is used for the emitted events when they are error events
- iOS: added an import for the crypto-digest headers - they are needed for the hash() function submitted in an earlier commit
- Fixed a link in the README.md - unfortunately the anchor-links change whenever even one character of the linked headline in the Wiki page changes
* Fix one issue raised in wkh237#477 by using code from https://stackoverflow.com/a/40874952/544779
* fix some access rights, remove unused items
* update gradle version setting in build.gradle
* Revert gradle settings to previous values :-(
* add a missing closing ")"
* Removed the part of an obsolete callback function parameter that I had left in when I converted mkdir to promises (low-level code)
* let mkdir resolve with "undefined" instead of "null" (my mistake)
* mkdir: normalize iOS and Android error if something already exists (file OR folder); return "true" (boolean) on success (failure is rejected promise) - it is not possibel to return "undefined" from a React Native promise from Java
* fix a long/int issue
* my mistake - according to https://facebook.github.io/react-native/docs/native-modules-android.html#argument-types "long" is not possible as argument type of an exported RN native module function
* Adde "utf8" as default encoding for fs.readFile - fixesjoltup#450 and joltup#484
* follow my IDEA IDE's recommendations - SparseArray instead of HashMap, and make some fields private
* polyfill/File.js: add a parameter===undefined? check (this happened silently in the test suite)
* make var static again
* Normalized errors for fs.ls()
* forgot one parameter
* more parameter checks
* forgot to resolve the promise
* Forgot ;
* add more error parameter checks
* change readStream()/writeStream() default encoding to utf8 to match the tests in react-native-fetch-blob-dev
* default encoding is set in fs.js (now), no need to do it twice
* ReadStream error events: Set a default error code "EUNSPECIFIED" if no code is returned (should not happen, actually)
* writeFile() Android and iOS: improve errors; ReadStream: Add "ENOENT" (no such file) error event to Android version and add the thus far missing "code" parameter to iOS version
* oops - one "}" too many - removed
* add EISDIR error to readFile()s error vocabulary (iOS and Android)
* "or directory" is misplaced in a "no such file" error message for readFile()
* Android: two reject() calls did not have a code, iOS: slice() did not have code EISDIR, and "could not resolve URI" now is EINVAL everywhere
* writeStream: return ENOENT, EISDIR and EUNSPECIFIED according to the normalized schema (joltup#460); Open a new question about behavior on ENOENT (joltup#491)
* "+ +" was one plus sign too many
* this if has a whole block (that ois why I prefer a style where {} are mandatory even for single-statement blocks)
* I renamed this variable
* 1) joltup#491 "writeStream() does not create file if it doesn't exist?"
2) I had gone overboard with the "@[..]" in the ios code, making some error strings arrays
3) fix typos: rename all ENODIR => ENOTDIR
* Java: getParentFolder() may return null - prevent a NullPointerException by adding one more check
* Relating to joltup#298 -- looping through an array is not supposed to be done with for...in
* Fix IOS syntax errors in joltup#489
* joltup#489 Fix typo and missing return statement
* fix error code
When using `writeStream`, the stream object becomes writable, and you can then perform operations like `write` and `close`.
646
647
648
+
Since version 0.10.9 `write()` resolves with the `RNFetchBlob` instance so you can promise-chain write calls:
649
+
650
+
```js
651
+
RNFetchBlob.fs.writeStream(
652
+
PATH_TO_FILE,
653
+
// encoding, should be one of `base64`, `utf8`, `ascii`
654
+
'utf8',
655
+
// should data append to existing content ?
656
+
true
657
+
)
658
+
.then(ofstream=>ofstream.write('foo'))
659
+
.then(ofstream=>ofstream.write('bar'))
660
+
.then(ofstream=>ofstream.write('foobar'))
661
+
.then(ofstream=>ofstream.close())
662
+
.catch(console.error)
663
+
```
664
+
665
+
or
666
+
667
+
```js
668
+
RNFetchBlob.fs.writeStream(
669
+
PATH_TO_FILE,
670
+
// encoding, should be one of `base64`, `utf8`, `ascii`
671
+
'utf8',
672
+
// should data append to existing content ?
673
+
true
674
+
)
675
+
.then(stream=>Promise.all([
676
+
stream.write('foo'),
677
+
stream.write('bar'),
678
+
stream.write('foobar')
679
+
]))
680
+
// Use array destructuring to get the stream object from the first item of the array we get from Promise.all()
681
+
.then(([stream]) =>stream.close())
682
+
.catch(console.error)
683
+
```
684
+
685
+
You should **NOT** do something like this:
686
+
647
687
```js
648
688
RNFetchBlob.fs.writeStream(
649
689
PATH_TO_FILE,
@@ -652,13 +692,18 @@ RNFetchBlob.fs.writeStream(
652
692
// should data append to existing content ?
653
693
true)
654
694
.then((ofstream) => {
695
+
// BAD IDEA - Don't do this, those writes are unchecked:
655
696
ofstream.write('foo')
656
697
ofstream.write('bar')
657
698
ofstream.close()
658
699
})
659
-
700
+
.catch(console.error) // Cannot catch any write() errors!
660
701
```
661
702
703
+
The problem with the above code is that the promises from the `ofstream.write()` calls are detached and "Lost".
704
+
That means the entire promise chain A) resolves without waiting for the writes to finish and B) any errors caused by them are lost.
705
+
That code may _seem_ to work if there are no errors, but those writes are of the type "fire and forget": You start them and then turn away and never know if they really succeeded.
706
+
662
707
### Cache File Management
663
708
664
709
When using `fileCache` or `path` options along with `fetch` API, response data will automatically store into the file system. The files will **NOT** removed unless you `unlink` it. There're several ways to remove the files
promise.reject("RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"), "RNFetchblob.addCompleteDownload can not resolve URI:" + path);
358
+
promise.reject("EINVAL", "RNFetchblob.addCompleteDownload can not resolve URI:" + config.getString("path"));
RNFetchBlobUtils.emitWarningEvent("RNFetchBlob multipart request builder has found a field without `data` property, the field `"+ field.name +"` will be removed implicitly.");
306
301
}
307
302
elseif (field.filename != null) {
303
+
Stringdata = field.data;
308
304
// upload from storage
309
305
if (data.startsWith(RNFetchBlobConst.FILE_PREFIX)) {
0 commit comments