forked from wkh237/react-native-fetch-blob
-
Notifications
You must be signed in to change notification settings - Fork 0
/
json-stream.js
39 lines (32 loc) · 1004 Bytes
/
json-stream.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import Oboe from './lib/oboe-browser.min.js'
import XMLHttpRequest from './polyfill/XMLHttpRequest'
import URIUtil from './utils/uri'
const OboeExtended = (arg: string | object) => {
window.location = ''
if(!window.XMLHttpRequest.isRNFBPolyfill ) {
window.XMLHttpRequest = XMLHttpRequest
console.warn('Use JSONStream will automatically replace window.XMLHttpRequest with RNFetchBlob.polyfill.XMLHttpRequest. You are seeing this warning because you did not replace it maually.')
}
if(typeof arg === 'string') {
if(URIUtil.isFileURI(arg)) {
arg = {
url : 'JSONStream://' + arg,
headers : { noCache : true }
}
}
else
arg = 'JSONStream://' + arg
}
else if(typeof arg === 'object') {
let headers = arg.headers || {}
if(URIUtil.isFileURI(arg.url)) {
headers.noCache = true
}
arg = Object.assign(arg, {
url : 'JSONStream://' + arg.url,
headers
})
}
return Oboe(arg)
}
export default OboeExtended