react-native-blob-util 0.19.0 → 0.19.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.js +56 -56
- package/LICENSE +21 -21
- package/Migration.md +41 -41
- package/README.md +1071 -1071
- package/android/gradle.properties +1 -1
- package/android/proguard-rules.pro +17 -17
- package/android/src/main/AndroidManifest.xml +39 -40
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConfig.java +57 -57
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilConst.java +20 -20
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFS.java +2 -2
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilFileTransformer.java +9 -9
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilImpl.java +431 -431
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilProgressConfig.java +39 -39
- package/android/src/main/java/com/ReactNativeBlobUtil/ReactNativeBlobUtilReq.java +972 -968
- package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilDefaultResp.java +98 -98
- package/android/src/main/java/com/ReactNativeBlobUtil/Response/ReactNativeBlobUtilFileResp.java +157 -157
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileDescription.java +19 -19
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/FileProvider.java +4 -4
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/MimeType.java +70 -70
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/PathResolver.java +223 -223
- package/android/src/main/java/com/ReactNativeBlobUtil/Utils/Tls12SocketFactory.java +68 -68
- package/android/src/main/res/values/strings.xml +3 -3
- package/android/src/main/res/xml/provider_paths.xml +12 -12
- package/android/src/newarch/java/com/ReactNativeBlobUtil/ReactNativeBlobUtil.java +1 -1
- package/android.js +58 -58
- package/class/ReactNativeBlobUtilCanceledFetchError.js +9 -9
- package/class/ReactNativeBlobUtilFile.js +5 -5
- package/class/ReactNativeBlobUtilReadStream.js +84 -84
- package/class/ReactNativeBlobUtilSession.js +68 -68
- package/class/ReactNativeBlobUtilWriteStream.js +50 -50
- package/class/StatefulPromise.js +7 -7
- package/codegenSpecs/NativeBlobUtils.js +86 -82
- package/components/Fetch.onPress.js +10 -10
- package/components/Fetch.when.js +15 -15
- package/fetch.js +344 -344
- package/fs.js +480 -480
- package/index.d.ts +871 -871
- package/index.js +64 -64
- package/index.js.flow +191 -191
- package/index.web.js +1 -1
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.h +55 -55
- package/ios/ReactNativeBlobUtil/ReactNativeBlobUtil.mm +993 -993
- package/ios/ReactNativeBlobUtil.xcodeproj/project.pbxproj +403 -403
- package/ios/ReactNativeBlobUtilConst.h +58 -58
- package/ios/ReactNativeBlobUtilConst.mm +47 -47
- package/ios/ReactNativeBlobUtilFS.h +108 -108
- package/ios/ReactNativeBlobUtilFS.mm +977 -977
- package/ios/ReactNativeBlobUtilFileTransformer.h +23 -23
- package/ios/ReactNativeBlobUtilFileTransformer.mm +20 -20
- package/ios/ReactNativeBlobUtilNetwork.h +49 -49
- package/ios/ReactNativeBlobUtilNetwork.mm +159 -159
- package/ios/ReactNativeBlobUtilProgress.h +32 -32
- package/ios/ReactNativeBlobUtilProgress.mm +57 -57
- package/ios/ReactNativeBlobUtilReqBuilder.h +37 -37
- package/ios/ReactNativeBlobUtilReqBuilder.mm +292 -292
- package/ios/ReactNativeBlobUtilRequest.h +48 -48
- package/ios/ReactNativeBlobUtilRequest.mm +535 -535
- package/ios.js +61 -61
- package/json-stream.js +42 -42
- package/lib/oboe-browser.js +2703 -2703
- package/mediacollection.js +36 -36
- package/package.json +55 -55
- package/polyfill/Blob.js +362 -362
- package/polyfill/Event.js +11 -11
- package/polyfill/EventTarget.js +78 -78
- package/polyfill/Fetch.js +219 -219
- package/polyfill/File.js +27 -27
- package/polyfill/FileReader.js +91 -91
- package/polyfill/ProgressEvent.js +32 -32
- package/polyfill/XMLHttpRequest.js +466 -466
- package/polyfill/XMLHttpRequestEventTarget.js +126 -126
- package/polyfill/index.js +11 -11
- package/react-native-blob-util.podspec +45 -45
- package/types.js +69 -69
- package/utils/log.js +40 -40
- package/utils/unicode.js +7 -7
- package/utils/uri.js +33 -33
- package/utils/uuid.js +4 -4
- package/windows/README.md +2 -2
- package/windows/ReactNativeBlobUtil/PropertySheet.props +15 -15
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.cpp +1701 -1693
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.def +3 -3
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.h +379 -366
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj +181 -181
- package/windows/ReactNativeBlobUtil/ReactNativeBlobUtil.vcxproj.filters +31 -31
- package/windows/ReactNativeBlobUtil/ReactPackageProvider.cpp +15 -15
- package/windows/ReactNativeBlobUtil/ReactPackageProvider.h +20 -20
- package/windows/ReactNativeBlobUtil/ReactPackageProvider.idl +9 -9
- package/windows/ReactNativeBlobUtil/packages.config +3 -3
- package/windows/ReactNativeBlobUtil/pch.cpp +1 -1
- package/windows/ReactNativeBlobUtil/pch.h +3 -3
|
@@ -1,69 +1,69 @@
|
|
|
1
|
-
package com.ReactNativeBlobUtil.Utils;
|
|
2
|
-
|
|
3
|
-
import java.io.IOException;
|
|
4
|
-
import java.net.InetAddress;
|
|
5
|
-
import java.net.Socket;
|
|
6
|
-
import java.net.UnknownHostException;
|
|
7
|
-
|
|
8
|
-
import javax.net.ssl.SSLSocket;
|
|
9
|
-
import javax.net.ssl.SSLSocketFactory;
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Enables TLS v1.2 when creating SSLSockets.
|
|
13
|
-
* For some reason, android supports TLS v1.2 from API 16, but enables it by
|
|
14
|
-
* default only from API 20.
|
|
15
|
-
*
|
|
16
|
-
* @see <a href='https://developer.android.com/reference/javax/net/ssl/SSLSocket.html'>Reference on SSLSocket</a>
|
|
17
|
-
* @see SSLSocketFactory
|
|
18
|
-
*/
|
|
19
|
-
public class Tls12SocketFactory extends SSLSocketFactory {
|
|
20
|
-
private static final String[] TLS_V12_ONLY = {"TLSv1.2"};
|
|
21
|
-
|
|
22
|
-
final SSLSocketFactory delegate;
|
|
23
|
-
|
|
24
|
-
public Tls12SocketFactory(SSLSocketFactory base) {
|
|
25
|
-
this.delegate = base;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
@Override
|
|
29
|
-
public String[] getDefaultCipherSuites() {
|
|
30
|
-
return delegate.getDefaultCipherSuites();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@Override
|
|
34
|
-
public String[] getSupportedCipherSuites() {
|
|
35
|
-
return delegate.getSupportedCipherSuites();
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
@Override
|
|
39
|
-
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
|
|
40
|
-
return patch(delegate.createSocket(s, host, port, autoClose));
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
@Override
|
|
44
|
-
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
|
45
|
-
return patch(delegate.createSocket(host, port));
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
@Override
|
|
49
|
-
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
|
|
50
|
-
return patch(delegate.createSocket(host, port, localHost, localPort));
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
@Override
|
|
54
|
-
public Socket createSocket(InetAddress host, int port) throws IOException {
|
|
55
|
-
return patch(delegate.createSocket(host, port));
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
@Override
|
|
59
|
-
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
|
60
|
-
return patch(delegate.createSocket(address, port, localAddress, localPort));
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
private Socket patch(Socket s) {
|
|
64
|
-
if (s instanceof SSLSocket) {
|
|
65
|
-
((SSLSocket) s).setEnabledProtocols(TLS_V12_ONLY);
|
|
66
|
-
}
|
|
67
|
-
return s;
|
|
68
|
-
}
|
|
1
|
+
package com.ReactNativeBlobUtil.Utils;
|
|
2
|
+
|
|
3
|
+
import java.io.IOException;
|
|
4
|
+
import java.net.InetAddress;
|
|
5
|
+
import java.net.Socket;
|
|
6
|
+
import java.net.UnknownHostException;
|
|
7
|
+
|
|
8
|
+
import javax.net.ssl.SSLSocket;
|
|
9
|
+
import javax.net.ssl.SSLSocketFactory;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Enables TLS v1.2 when creating SSLSockets.
|
|
13
|
+
* For some reason, android supports TLS v1.2 from API 16, but enables it by
|
|
14
|
+
* default only from API 20.
|
|
15
|
+
*
|
|
16
|
+
* @see <a href='https://developer.android.com/reference/javax/net/ssl/SSLSocket.html'>Reference on SSLSocket</a>
|
|
17
|
+
* @see SSLSocketFactory
|
|
18
|
+
*/
|
|
19
|
+
public class Tls12SocketFactory extends SSLSocketFactory {
|
|
20
|
+
private static final String[] TLS_V12_ONLY = {"TLSv1.2"};
|
|
21
|
+
|
|
22
|
+
final SSLSocketFactory delegate;
|
|
23
|
+
|
|
24
|
+
public Tls12SocketFactory(SSLSocketFactory base) {
|
|
25
|
+
this.delegate = base;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
@Override
|
|
29
|
+
public String[] getDefaultCipherSuites() {
|
|
30
|
+
return delegate.getDefaultCipherSuites();
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@Override
|
|
34
|
+
public String[] getSupportedCipherSuites() {
|
|
35
|
+
return delegate.getSupportedCipherSuites();
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
@Override
|
|
39
|
+
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
|
|
40
|
+
return patch(delegate.createSocket(s, host, port, autoClose));
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Override
|
|
44
|
+
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
|
|
45
|
+
return patch(delegate.createSocket(host, port));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
@Override
|
|
49
|
+
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
|
|
50
|
+
return patch(delegate.createSocket(host, port, localHost, localPort));
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
@Override
|
|
54
|
+
public Socket createSocket(InetAddress host, int port) throws IOException {
|
|
55
|
+
return patch(delegate.createSocket(host, port));
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Override
|
|
59
|
+
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
|
|
60
|
+
return patch(delegate.createSocket(address, port, localAddress, localPort));
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private Socket patch(Socket s) {
|
|
64
|
+
if (s instanceof SSLSocket) {
|
|
65
|
+
((SSLSocket) s).setEnabledProtocols(TLS_V12_ONLY);
|
|
66
|
+
}
|
|
67
|
+
return s;
|
|
68
|
+
}
|
|
69
69
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
<resources>
|
|
2
|
-
<string name="app_name">react-native-blob-util</string>
|
|
3
|
-
</resources>
|
|
1
|
+
<resources>
|
|
2
|
+
<string name="app_name">react-native-blob-util</string>
|
|
3
|
+
</resources>
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
-
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
-
<external-path
|
|
4
|
-
name="external_files"
|
|
5
|
-
path="." />
|
|
6
|
-
<files-path
|
|
7
|
-
name="files-path"
|
|
8
|
-
path="." /> <!-- Used to access into application data files -->
|
|
9
|
-
<cache-path
|
|
10
|
-
name="cache-path"
|
|
11
|
-
path="." /> <!-- Used to access files in cache directory -->
|
|
12
|
-
</paths>
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
|
2
|
+
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
|
3
|
+
<external-path
|
|
4
|
+
name="external_files"
|
|
5
|
+
path="." />
|
|
6
|
+
<files-path
|
|
7
|
+
name="files-path"
|
|
8
|
+
path="." /> <!-- Used to access into application data files -->
|
|
9
|
+
<cache-path
|
|
10
|
+
name="cache-path"
|
|
11
|
+
path="." /> <!-- Used to access files in cache directory -->
|
|
12
|
+
</paths>
|
package/android.js
CHANGED
|
@@ -1,58 +1,58 @@
|
|
|
1
|
-
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
-
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
import { Platform } from 'react-native';
|
|
6
|
-
import ReactNativeBlobUtil from './codegenSpecs/NativeBlobUtils';
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* Send an intent to open the file.
|
|
10
|
-
* @param {string} path Path of the file to be open.
|
|
11
|
-
* @param {string} mime MIME type string
|
|
12
|
-
* @param {string} chooserTitle for chooser, if not set the chooser won't be displayed (see https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence))
|
|
13
|
-
* @return {Promise}
|
|
14
|
-
*/
|
|
15
|
-
function actionViewIntent(path, mime, chooserTitle) {
|
|
16
|
-
if(typeof chooserTitle === 'undefined') chooserTitle = null;
|
|
17
|
-
if(Platform.OS === 'android')
|
|
18
|
-
return ReactNativeBlobUtil.actionViewIntent(path, mime, chooserTitle);
|
|
19
|
-
else
|
|
20
|
-
return Promise.reject('ReactNativeBlobUtil.android.actionViewIntent only supports Android.');
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function getContentIntent(mime) {
|
|
24
|
-
if(Platform.OS === 'android')
|
|
25
|
-
return ReactNativeBlobUtil.getContentIntent(mime);
|
|
26
|
-
else
|
|
27
|
-
return Promise.reject('ReactNativeBlobUtil.android.getContentIntent only supports Android.');
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function addCompleteDownload(config) {
|
|
31
|
-
if(Platform.OS === 'android')
|
|
32
|
-
return ReactNativeBlobUtil.addCompleteDownload(config);
|
|
33
|
-
else
|
|
34
|
-
return Promise.reject('ReactNativeBlobUtil.android.addCompleteDownload only supports Android.');
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function getSDCardDir() {
|
|
38
|
-
if(Platform.OS === 'android')
|
|
39
|
-
return ReactNativeBlobUtil.getSDCardDir();
|
|
40
|
-
else
|
|
41
|
-
return Promise.reject('ReactNativeBlobUtil.android.getSDCardDir only supports Android.');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
function getSDCardApplicationDir() {
|
|
45
|
-
if(Platform.OS === 'android')
|
|
46
|
-
return ReactNativeBlobUtil.getSDCardApplicationDir();
|
|
47
|
-
else
|
|
48
|
-
return Promise.reject('ReactNativeBlobUtil.android.getSDCardApplicationDir only supports Android.');
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export default {
|
|
53
|
-
actionViewIntent,
|
|
54
|
-
getContentIntent,
|
|
55
|
-
addCompleteDownload,
|
|
56
|
-
getSDCardDir,
|
|
57
|
-
getSDCardApplicationDir,
|
|
58
|
-
};
|
|
1
|
+
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import { Platform } from 'react-native';
|
|
6
|
+
import ReactNativeBlobUtil from './codegenSpecs/NativeBlobUtils';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Send an intent to open the file.
|
|
10
|
+
* @param {string} path Path of the file to be open.
|
|
11
|
+
* @param {string} mime MIME type string
|
|
12
|
+
* @param {string} chooserTitle for chooser, if not set the chooser won't be displayed (see https://developer.android.com/reference/android/content/Intent.html#createChooser(android.content.Intent,%20java.lang.CharSequence))
|
|
13
|
+
* @return {Promise}
|
|
14
|
+
*/
|
|
15
|
+
function actionViewIntent(path, mime, chooserTitle) {
|
|
16
|
+
if(typeof chooserTitle === 'undefined') chooserTitle = null;
|
|
17
|
+
if(Platform.OS === 'android')
|
|
18
|
+
return ReactNativeBlobUtil.actionViewIntent(path, mime, chooserTitle);
|
|
19
|
+
else
|
|
20
|
+
return Promise.reject('ReactNativeBlobUtil.android.actionViewIntent only supports Android.');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function getContentIntent(mime) {
|
|
24
|
+
if(Platform.OS === 'android')
|
|
25
|
+
return ReactNativeBlobUtil.getContentIntent(mime);
|
|
26
|
+
else
|
|
27
|
+
return Promise.reject('ReactNativeBlobUtil.android.getContentIntent only supports Android.');
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
function addCompleteDownload(config) {
|
|
31
|
+
if(Platform.OS === 'android')
|
|
32
|
+
return ReactNativeBlobUtil.addCompleteDownload(config);
|
|
33
|
+
else
|
|
34
|
+
return Promise.reject('ReactNativeBlobUtil.android.addCompleteDownload only supports Android.');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function getSDCardDir() {
|
|
38
|
+
if(Platform.OS === 'android')
|
|
39
|
+
return ReactNativeBlobUtil.getSDCardDir();
|
|
40
|
+
else
|
|
41
|
+
return Promise.reject('ReactNativeBlobUtil.android.getSDCardDir only supports Android.');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getSDCardApplicationDir() {
|
|
45
|
+
if(Platform.OS === 'android')
|
|
46
|
+
return ReactNativeBlobUtil.getSDCardApplicationDir();
|
|
47
|
+
else
|
|
48
|
+
return Promise.reject('ReactNativeBlobUtil.android.getSDCardApplicationDir only supports Android.');
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
export default {
|
|
53
|
+
actionViewIntent,
|
|
54
|
+
getContentIntent,
|
|
55
|
+
addCompleteDownload,
|
|
56
|
+
getSDCardDir,
|
|
57
|
+
getSDCardApplicationDir,
|
|
58
|
+
};
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
const CANCELED_FETCH_ERROR_NAME = 'ReactNativeBlobUtilCanceledFetch'
|
|
2
|
-
|
|
3
|
-
class CanceledFetchError extends Error {
|
|
4
|
-
constructor(message) {
|
|
5
|
-
super(message);
|
|
6
|
-
this.name = CANCELED_FETCH_ERROR_NAME
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
|
|
1
|
+
const CANCELED_FETCH_ERROR_NAME = 'ReactNativeBlobUtilCanceledFetch'
|
|
2
|
+
|
|
3
|
+
class CanceledFetchError extends Error {
|
|
4
|
+
constructor(message) {
|
|
5
|
+
super(message);
|
|
6
|
+
this.name = CANCELED_FETCH_ERROR_NAME
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
10
|
export default CanceledFetchError
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
-
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
export default class ReactNativeBlobUtilFile {}
|
|
1
|
+
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
export default class ReactNativeBlobUtilFile {}
|
|
@@ -1,84 +1,84 @@
|
|
|
1
|
-
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
-
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
import {NativeEventEmitter} from 'react-native';
|
|
6
|
-
import UUID from '../utils/uuid';
|
|
7
|
-
|
|
8
|
-
import ReactNativeBlobUtil from '../codegenSpecs/NativeBlobUtils';
|
|
9
|
-
|
|
10
|
-
const emitter = new NativeEventEmitter(ReactNativeBlobUtil);
|
|
11
|
-
|
|
12
|
-
export default class ReactNativeBlobUtilReadStream {
|
|
13
|
-
|
|
14
|
-
path: string;
|
|
15
|
-
encoding: 'utf8' | 'ascii' | 'base64';
|
|
16
|
-
bufferSize: ?number;
|
|
17
|
-
closed: boolean;
|
|
18
|
-
tick: number = 10;
|
|
19
|
-
|
|
20
|
-
constructor(path: string, encoding: string, bufferSize?: ?number, tick: number) {
|
|
21
|
-
if (!path)
|
|
22
|
-
throw Error('ReactNativeBlobUtil could not open file stream with empty `path`');
|
|
23
|
-
this.encoding = encoding || 'utf8';
|
|
24
|
-
this.bufferSize = bufferSize;
|
|
25
|
-
this.path = path;
|
|
26
|
-
this.closed = false;
|
|
27
|
-
this.tick = tick;
|
|
28
|
-
this._onData = () => {
|
|
29
|
-
};
|
|
30
|
-
this._onEnd = () => {
|
|
31
|
-
};
|
|
32
|
-
this._onError = () => {
|
|
33
|
-
};
|
|
34
|
-
this.streamId = 'RNFBRS' + UUID();
|
|
35
|
-
|
|
36
|
-
// register for file stream event
|
|
37
|
-
let subscription = emitter.addListener('ReactNativeBlobUtilFilesystem', (e) => {
|
|
38
|
-
if (typeof e === 'string') e = JSON.parse(e);
|
|
39
|
-
if (e.streamId !== this.streamId) return; // wrong stream
|
|
40
|
-
let {event, code, detail} = e;
|
|
41
|
-
if (this._onData && event === 'data') {
|
|
42
|
-
this._onData(detail);
|
|
43
|
-
return;
|
|
44
|
-
}
|
|
45
|
-
else if (this._onEnd && event === 'end') {
|
|
46
|
-
this._onEnd(detail);
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
const err = new Error(detail);
|
|
50
|
-
err.code = code || 'EUNSPECIFIED';
|
|
51
|
-
if (this._onError)
|
|
52
|
-
this._onError(err);
|
|
53
|
-
else
|
|
54
|
-
throw err;
|
|
55
|
-
}
|
|
56
|
-
// when stream closed or error, remove event handler
|
|
57
|
-
if (event === 'error' || event === 'end') {
|
|
58
|
-
subscription.remove();
|
|
59
|
-
this.closed = true;
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
open() {
|
|
66
|
-
if (!this.closed)
|
|
67
|
-
ReactNativeBlobUtil.readStream(this.path, this.encoding, this.bufferSize || 10240, this.tick || -1, this.streamId);
|
|
68
|
-
else
|
|
69
|
-
throw new Error('Stream closed');
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
onData(fn: () => void) {
|
|
73
|
-
this._onData = fn;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
onError(fn) {
|
|
77
|
-
this._onError = fn;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
onEnd(fn) {
|
|
81
|
-
this._onEnd = fn;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}
|
|
1
|
+
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import {NativeEventEmitter} from 'react-native';
|
|
6
|
+
import UUID from '../utils/uuid';
|
|
7
|
+
|
|
8
|
+
import ReactNativeBlobUtil from '../codegenSpecs/NativeBlobUtils';
|
|
9
|
+
|
|
10
|
+
const emitter = new NativeEventEmitter(ReactNativeBlobUtil);
|
|
11
|
+
|
|
12
|
+
export default class ReactNativeBlobUtilReadStream {
|
|
13
|
+
|
|
14
|
+
path: string;
|
|
15
|
+
encoding: 'utf8' | 'ascii' | 'base64';
|
|
16
|
+
bufferSize: ?number;
|
|
17
|
+
closed: boolean;
|
|
18
|
+
tick: number = 10;
|
|
19
|
+
|
|
20
|
+
constructor(path: string, encoding: string, bufferSize?: ?number, tick: number) {
|
|
21
|
+
if (!path)
|
|
22
|
+
throw Error('ReactNativeBlobUtil could not open file stream with empty `path`');
|
|
23
|
+
this.encoding = encoding || 'utf8';
|
|
24
|
+
this.bufferSize = bufferSize;
|
|
25
|
+
this.path = path;
|
|
26
|
+
this.closed = false;
|
|
27
|
+
this.tick = tick;
|
|
28
|
+
this._onData = () => {
|
|
29
|
+
};
|
|
30
|
+
this._onEnd = () => {
|
|
31
|
+
};
|
|
32
|
+
this._onError = () => {
|
|
33
|
+
};
|
|
34
|
+
this.streamId = 'RNFBRS' + UUID();
|
|
35
|
+
|
|
36
|
+
// register for file stream event
|
|
37
|
+
let subscription = emitter.addListener('ReactNativeBlobUtilFilesystem', (e) => {
|
|
38
|
+
if (typeof e === 'string') e = JSON.parse(e);
|
|
39
|
+
if (e.streamId !== this.streamId) return; // wrong stream
|
|
40
|
+
let {event, code, detail} = e;
|
|
41
|
+
if (this._onData && event === 'data') {
|
|
42
|
+
this._onData(detail);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
else if (this._onEnd && event === 'end') {
|
|
46
|
+
this._onEnd(detail);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
const err = new Error(detail);
|
|
50
|
+
err.code = code || 'EUNSPECIFIED';
|
|
51
|
+
if (this._onError)
|
|
52
|
+
this._onError(err);
|
|
53
|
+
else
|
|
54
|
+
throw err;
|
|
55
|
+
}
|
|
56
|
+
// when stream closed or error, remove event handler
|
|
57
|
+
if (event === 'error' || event === 'end') {
|
|
58
|
+
subscription.remove();
|
|
59
|
+
this.closed = true;
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
open() {
|
|
66
|
+
if (!this.closed)
|
|
67
|
+
ReactNativeBlobUtil.readStream(this.path, this.encoding, this.bufferSize || 10240, this.tick || -1, this.streamId);
|
|
68
|
+
else
|
|
69
|
+
throw new Error('Stream closed');
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
onData(fn: () => void) {
|
|
73
|
+
this._onData = fn;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
onError(fn) {
|
|
77
|
+
this._onError = fn;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
onEnd(fn) {
|
|
81
|
+
this._onEnd = fn;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
}
|
|
@@ -1,68 +1,68 @@
|
|
|
1
|
-
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
-
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
-
// found in the LICENSE file.
|
|
4
|
-
|
|
5
|
-
import ReactNativeBlobUtil from '../codegenSpecs/NativeBlobUtils';
|
|
6
|
-
|
|
7
|
-
let sessions = {};
|
|
8
|
-
|
|
9
|
-
export default class ReactNativeBlobUtilSession {
|
|
10
|
-
|
|
11
|
-
name : string;
|
|
12
|
-
|
|
13
|
-
static getSession(name:string):any {
|
|
14
|
-
return sessions[name];
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
static setSession(name:string, val:any) {
|
|
18
|
-
sessions[name] = val;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
static removeSession(name:string) {
|
|
22
|
-
delete sessions[name];
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
constructor(name:string, list:Array<string>) {
|
|
26
|
-
this.name = name;
|
|
27
|
-
if (!sessions[name]) {
|
|
28
|
-
if (Array.isArray(list))
|
|
29
|
-
sessions[name] = list;
|
|
30
|
-
else
|
|
31
|
-
sessions[name] = [];
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
add(path:string):ReactNativeBlobUtilSession {
|
|
36
|
-
sessions[this.name].push(path);
|
|
37
|
-
return this;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
remove(path:string):ReactNativeBlobUtilSession {
|
|
41
|
-
let list = sessions[this.name];
|
|
42
|
-
for (let i of list) {
|
|
43
|
-
if (list[i] === path) {
|
|
44
|
-
sessions[this.name].splice(i, 1);
|
|
45
|
-
break;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return this;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
list():Array<string> {
|
|
52
|
-
return sessions[this.name];
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
dispose():Promise {
|
|
56
|
-
return new Promise((resolve, reject) => {
|
|
57
|
-
ReactNativeBlobUtil.removeSession(sessions[this.name], (err) => {
|
|
58
|
-
if (err)
|
|
59
|
-
reject(new Error(err));
|
|
60
|
-
else {
|
|
61
|
-
delete sessions[this.name];
|
|
62
|
-
resolve();
|
|
63
|
-
}
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
}
|
|
1
|
+
// Copyright 2016 wkh237@github. All rights reserved.
|
|
2
|
+
// Use of this source code is governed by a MIT-style license that can be
|
|
3
|
+
// found in the LICENSE file.
|
|
4
|
+
|
|
5
|
+
import ReactNativeBlobUtil from '../codegenSpecs/NativeBlobUtils';
|
|
6
|
+
|
|
7
|
+
let sessions = {};
|
|
8
|
+
|
|
9
|
+
export default class ReactNativeBlobUtilSession {
|
|
10
|
+
|
|
11
|
+
name : string;
|
|
12
|
+
|
|
13
|
+
static getSession(name:string):any {
|
|
14
|
+
return sessions[name];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static setSession(name:string, val:any) {
|
|
18
|
+
sessions[name] = val;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
static removeSession(name:string) {
|
|
22
|
+
delete sessions[name];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
constructor(name:string, list:Array<string>) {
|
|
26
|
+
this.name = name;
|
|
27
|
+
if (!sessions[name]) {
|
|
28
|
+
if (Array.isArray(list))
|
|
29
|
+
sessions[name] = list;
|
|
30
|
+
else
|
|
31
|
+
sessions[name] = [];
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
add(path:string):ReactNativeBlobUtilSession {
|
|
36
|
+
sessions[this.name].push(path);
|
|
37
|
+
return this;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
remove(path:string):ReactNativeBlobUtilSession {
|
|
41
|
+
let list = sessions[this.name];
|
|
42
|
+
for (let i of list) {
|
|
43
|
+
if (list[i] === path) {
|
|
44
|
+
sessions[this.name].splice(i, 1);
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return this;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
list():Array<string> {
|
|
52
|
+
return sessions[this.name];
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
dispose():Promise {
|
|
56
|
+
return new Promise((resolve, reject) => {
|
|
57
|
+
ReactNativeBlobUtil.removeSession(sessions[this.name], (err) => {
|
|
58
|
+
if (err)
|
|
59
|
+
reject(new Error(err));
|
|
60
|
+
else {
|
|
61
|
+
delete sessions[this.name];
|
|
62
|
+
resolve();
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
}
|