This repository was archived by the owner on Mar 10, 2020. It is now read-only.
File tree 21 files changed +32
-21
lines changed
21 files changed +32
-21
lines changed Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ module.exports = configure(({ ky }) => {
40
40
body : await toFormData ( input )
41
41
} )
42
42
43
- for await ( let file of ndjson ( toIterable ( res . body ) ) ) {
43
+ for await ( let file of ndjson ( toIterable ( res ) ) ) {
44
44
file = toCamel ( file )
45
45
// console.log(file)
46
46
if ( options . progress && file . bytes ) {
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ module.exports = configure(({ ky }) => {
30
30
searchParams
31
31
} )
32
32
33
- for await ( const removed of ndjson ( toIterable ( res . body ) ) ) {
33
+ for await ( const removed of ndjson ( toIterable ( res ) ) ) {
34
34
yield toCamel ( removed )
35
35
}
36
36
}
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ module.exports = configure(({ ky }) => {
27
27
searchParams
28
28
} )
29
29
30
- for await ( const chunk of toIterable ( res . body ) ) {
30
+ for await ( const chunk of toIterable ( res ) ) {
31
31
yield Buffer . from ( chunk )
32
32
}
33
33
}
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ module.exports = configure(({ ky }) => {
22
22
searchParams
23
23
} )
24
24
25
- for await ( const message of ndjson ( toIterable ( res . body ) ) ) {
25
+ for await ( const message of ndjson ( toIterable ( res ) ) ) {
26
26
// 2 = FinalPeer
27
27
// https://github.com/libp2p/go-libp2p-core/blob/6e566d10f4a5447317a66d64c7459954b969bdab/routing/query.go#L18
28
28
if ( message . Type === 2 && message . Responses ) {
Original file line number Diff line number Diff line change @@ -23,7 +23,7 @@ module.exports = configure(({ ky }) => {
23
23
searchParams
24
24
} )
25
25
26
- for await ( const message of ndjson ( toIterable ( res . body ) ) ) {
26
+ for await ( const message of ndjson ( toIterable ( res ) ) ) {
27
27
// 4 = Provider
28
28
// https://github.com/libp2p/go-libp2p-core/blob/6e566d10f4a5447317a66d64c7459954b969bdab/routing/query.go#L20
29
29
if ( message . Type === 4 && message . Responses ) {
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ module.exports = configure(({ ky }) => {
19
19
searchParams
20
20
} )
21
21
22
- for await ( const message of ndjson ( toIterable ( res . body ) ) ) {
22
+ for await ( const message of ndjson ( toIterable ( res ) ) ) {
23
23
// 5 = Value
24
24
// https://github.com/libp2p/go-libp2p-core/blob/6e566d10f4a5447317a66d64c7459954b969bdab/routing/query.go#L21
25
25
if ( message . Type === 5 ) {
Original file line number Diff line number Diff line change @@ -25,7 +25,7 @@ module.exports = configure(({ ky }) => {
25
25
searchParams
26
26
} )
27
27
28
- for await ( let message of ndjson ( toIterable ( res . body ) ) ) {
28
+ for await ( let message of ndjson ( toIterable ( res ) ) ) {
29
29
message = toCamel ( message )
30
30
if ( message . responses ) {
31
31
message . responses = message . responses . map ( ( { ID , Addrs } ) => {
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ module.exports = configure(({ ky }) => {
26
26
headers : options . headers
27
27
} )
28
28
29
- for await ( let message of ndjson ( toIterable ( res . body ) ) ) {
29
+ for await ( let message of ndjson ( toIterable ( res ) ) ) {
30
30
message = toCamel ( message )
31
31
if ( message . responses ) {
32
32
message . responses = message . responses . map ( ( { ID , Addrs } ) => {
Original file line number Diff line number Diff line change @@ -21,7 +21,7 @@ module.exports = configure(({ ky }) => {
21
21
searchParams
22
22
} )
23
23
24
- for await ( const message of ndjson ( toIterable ( res . body ) ) ) {
24
+ for await ( const message of ndjson ( toIterable ( res ) ) ) {
25
25
yield new PeerInfo ( PeerId . createFromB58String ( message . ID ) )
26
26
}
27
27
}
Original file line number Diff line number Diff line change @@ -28,7 +28,7 @@ module.exports = configure(({ ky }) => {
28
28
searchParams
29
29
} )
30
30
31
- for await ( const result of ndjson ( toIterable ( res . body ) ) ) {
31
+ for await ( const result of ndjson ( toIterable ( res ) ) ) {
32
32
// go-ipfs does not yet support the "stream" option
33
33
if ( 'Entries' in result ) {
34
34
for ( const entry of result . Entries || [ ] ) {
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module.exports = configure(({ ky }) => {
20
20
searchParams
21
21
} )
22
22
23
- for await ( const chunk of toIterable ( res . body ) ) {
23
+ for await ( const chunk of toIterable ( res ) ) {
24
24
yield Buffer . from ( chunk )
25
25
}
26
26
}
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ module.exports = configure(({ ky }) => {
38
38
39
39
const extractor = Tar . extract ( )
40
40
41
- for await ( const { header, body } of extractor ( toIterable ( res . body ) ) ) {
41
+ for await ( const { header, body } of extractor ( toIterable ( res ) ) ) {
42
42
if ( header . type === 'directory' ) {
43
43
yield {
44
44
path : header . name
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
- module . exports = function toIterable ( body ) {
3
+ module . exports = function toIterable ( res ) {
4
+ // An env where res.body getter for ReadableStream with getReader
5
+ // is not supported, for example in React Native
6
+ if ( ! res . body ) {
7
+ return ( async function * ( ) {
8
+ const arrayBuffer = await res . arrayBuffer ( )
9
+ yield arrayBuffer
10
+ } ) ( )
11
+ }
12
+
13
+ const { body } = res
14
+
4
15
// Node.js stream
5
16
if ( body [ Symbol . asyncIterator ] ) return body
6
17
Original file line number Diff line number Diff line change @@ -15,6 +15,6 @@ module.exports = configure(({ ky }) => {
15
15
searchParams : options . searchParams
16
16
} )
17
17
18
- yield * ndjson ( toIterable ( res . body ) )
18
+ yield * ndjson ( toIterable ( res ) )
19
19
}
20
20
} )
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ module.exports = configure(({ ky }) => {
19
19
searchParams
20
20
} )
21
21
22
- for await ( const chunk of toIterable ( res . body ) ) {
22
+ for await ( const chunk of toIterable ( res ) ) {
23
23
yield Buffer . from ( chunk )
24
24
}
25
25
}
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ module.exports = configure(({ ky }) => {
20
20
searchParams
21
21
} )
22
22
23
- for await ( const chunk of ndjson ( toIterable ( res . body ) ) ) {
23
+ for await ( const chunk of ndjson ( toIterable ( res ) ) ) {
24
24
yield toCamel ( chunk )
25
25
}
26
26
}
Original file line number Diff line number Diff line change @@ -50,7 +50,7 @@ module.exports = configure((config) => {
50
50
51
51
clearTimeout ( ffWorkaround )
52
52
53
- readMessages ( ndjson ( toIterable ( res . body ) ) , {
53
+ readMessages ( ndjson ( toIterable ( res ) ) , {
54
54
onMessage : handler ,
55
55
onEnd : ( ) => subsTracker . unsubscribe ( topic , handler ) ,
56
56
onError : options . onError
Original file line number Diff line number Diff line change @@ -49,7 +49,7 @@ module.exports = config => {
49
49
searchParams
50
50
} )
51
51
52
- for await ( const file of ndjson ( toIterable ( res . body ) ) ) {
52
+ for await ( const file of ndjson ( toIterable ( res ) ) ) {
53
53
yield toCamel ( file )
54
54
}
55
55
}
Original file line number Diff line number Diff line change @@ -15,7 +15,7 @@ module.exports = configure(({ ky }) => {
15
15
headers : options . headers
16
16
} )
17
17
18
- for await ( const file of ndjson ( toIterable ( res . body ) ) ) {
18
+ for await ( const file of ndjson ( toIterable ( res ) ) ) {
19
19
yield toCamel ( file )
20
20
}
21
21
}
Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ module.exports = configure(({ ky }) => {
19
19
searchParams
20
20
} )
21
21
22
- for await ( const gcResult of ndjson ( toIterable ( res . body ) ) ) {
22
+ for await ( const gcResult of ndjson ( toIterable ( res ) ) ) {
23
23
yield {
24
24
err : gcResult . Error ? new Error ( gcResult . Error ) : null ,
25
25
cid : ( gcResult . Key || { } ) [ '/' ] ? new CID ( gcResult . Key [ '/' ] ) : null
Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ module.exports = configure(({ ky }) => {
22
22
searchParams
23
23
} )
24
24
25
- for await ( const stats of ndjson ( toIterable ( res . body ) ) ) {
25
+ for await ( const stats of ndjson ( toIterable ( res ) ) ) {
26
26
yield {
27
27
totalIn : new Big ( stats . TotalIn ) ,
28
28
totalOut : new Big ( stats . TotalOut ) ,
You can’t perform that action at this time.
0 commit comments