@@ -5,6 +5,8 @@ const { Buffer } = require('buffer')
5
5
const pullStreamToIterable = require ( 'pull-stream-to-async-iterator' )
6
6
const { isSource } = require ( 'is-pull-stream' )
7
7
const globalThis = require ( '../globalthis' )
8
+ const { Readable } = require ( 'stream' )
9
+ const Readable3 = require ( 'readable-stream' )
8
10
9
11
/*
10
12
* Transform one of:
@@ -20,6 +22,7 @@ const globalThis = require('../globalthis')
20
22
* { path, content: Iterable<Bytes> } [single file]
21
23
* { path, content: AsyncIterable<Bytes> } [single file]
22
24
* { path, content: PullStream<Bytes> } [single file]
25
+ * { path, content: Readable<Bytes> } [single file]
23
26
* Iterable<Number> [single file]
24
27
* Iterable<Bytes> [single file]
25
28
* Iterable<Bloby> [multiple files]
@@ -31,6 +34,7 @@ const globalThis = require('../globalthis')
31
34
* Iterable<{ path, content: Iterable<Bytes> }> [multiple files]
32
35
* Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
33
36
* Iterable<{ path, content: PullStream<Bytes> }> [multiple files]
37
+ * Iterable<{ path, content: Readable<Bytes> }> [multiple files]
34
38
* AsyncIterable<Bytes> [single file]
35
39
* AsyncIterable<Bloby> [multiple files]
36
40
* AsyncIterable<String> [multiple files]
@@ -41,6 +45,7 @@ const globalThis = require('../globalthis')
41
45
* AsyncIterable<{ path, content: Iterable<Bytes> }> [multiple files]
42
46
* AsyncIterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
43
47
* AsyncIterable<{ path, content: PullStream<Bytes> }> [multiple files]
48
+ * AsyncIterable<{ path, content: Readable<Bytes> }> [multiple files]
44
49
* PullStream<Bytes> [single file]
45
50
* PullStream<Bloby> [multiple files]
46
51
* PullStream<String> [multiple files]
@@ -51,6 +56,18 @@ const globalThis = require('../globalthis')
51
56
* PullStream<{ path, content: Iterable<Bytes> }> [multiple files]
52
57
* PullStream<{ path, content: AsyncIterable<Bytes> }> [multiple files]
53
58
* PullStream<{ path, content: PullStream<Bytes> }> [multiple files]
59
+ * PullStream<{ path, content: Readable<Bytes> }> [multiple files]
60
+ * Readable<Bytes> [single file]
61
+ * Readable<Bloby> [multiple files]
62
+ * Readable<String> [multiple files]
63
+ * Readable<{ path, content: Bytes }> [multiple files]
64
+ * Readable<{ path, content: Bloby }> [multiple files]
65
+ * Readable<{ path, content: String }> [multiple files]
66
+ * Readable<{ path, content: Iterable<Number> }> [multiple files]
67
+ * Readable<{ path, content: Iterable<Bytes> }> [multiple files]
68
+ * Readable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
69
+ * Readable<{ path, content: PullStream<Bytes> }> [multiple files]
70
+ * Readable<{ path, content: Readable<Bytes> }> [multiple files]
54
71
* ```
55
72
* Into:
56
73
*
@@ -82,6 +99,11 @@ module.exports = function normaliseInput (input) {
82
99
} ) ( )
83
100
}
84
101
102
+ // Readable<?>
103
+ if ( isOldReadable ( input ) ) {
104
+ input = upgradeOldStream ( input )
105
+ }
106
+
85
107
// Iterable<?>
86
108
if ( input [ Symbol . iterator ] ) {
87
109
return ( async function * ( ) { // eslint-disable-line require-await
@@ -213,6 +235,11 @@ function toAsyncIterable (input) {
213
235
return blobToAsyncGenerator ( input )
214
236
}
215
237
238
+ // Readable<?>
239
+ if ( isOldReadable ( input ) ) {
240
+ input = upgradeOldStream ( input )
241
+ }
242
+
216
243
// Iterator<?>
217
244
if ( input [ Symbol . iterator ] ) {
218
245
return ( async function * ( ) { // eslint-disable-line require-await
@@ -259,6 +286,14 @@ function toAsyncIterable (input) {
259
286
throw errCode ( new Error ( `Unexpected input: ${ input } ` , 'ERR_UNEXPECTED_INPUT' ) )
260
287
}
261
288
289
+ function isOldReadable ( obj ) {
290
+ if ( obj [ Symbol . iterator ] || obj [ Symbol . asyncIterator ] ) {
291
+ return false
292
+ }
293
+
294
+ return Boolean ( obj . readable )
295
+ }
296
+
262
297
function toBuffer ( chunk ) {
263
298
return isBytes ( chunk ) ? chunk : Buffer . from ( chunk )
264
299
}
@@ -276,6 +311,17 @@ function isFileObject (obj) {
276
311
return typeof obj === 'object' && ( obj . path || obj . content )
277
312
}
278
313
314
+ function upgradeOldStream ( stream ) {
315
+ if ( stream [ Symbol . asyncIterator ] || stream [ Symbol . iterator ] ) {
316
+ return stream
317
+ }
318
+
319
+ // in the browser the stream.Readable is not an async iterator but readble-stream@3 is...
320
+ stream [ Symbol . asyncIterator ] = Readable . prototype [ Symbol . asyncIterator ] || Readable3 . prototype [ Symbol . asyncIterator ]
321
+
322
+ return stream
323
+ }
324
+
279
325
function blobToAsyncGenerator ( blob ) {
280
326
if ( typeof blob . stream === 'function' ) {
281
327
// firefox < 69 does not support blob.stream()
0 commit comments