@@ -5,6 +5,8 @@ const { Buffer } = require('buffer')
55const pullStreamToIterable = require ( 'pull-stream-to-async-iterator' )
66const { isSource } = require ( 'is-pull-stream' )
77const globalThis = require ( '../globalthis' )
8+ const { Readable } = require ( 'stream' )
9+ const Readable3 = require ( 'readable-stream' )
810
911/*
1012 * Transform one of:
@@ -20,6 +22,7 @@ const globalThis = require('../globalthis')
2022 * { path, content: Iterable<Bytes> } [single file]
2123 * { path, content: AsyncIterable<Bytes> } [single file]
2224 * { path, content: PullStream<Bytes> } [single file]
25+ * { path, content: Readable<Bytes> } [single file]
2326 * Iterable<Number> [single file]
2427 * Iterable<Bytes> [single file]
2528 * Iterable<Bloby> [multiple files]
@@ -31,6 +34,7 @@ const globalThis = require('../globalthis')
3134 * Iterable<{ path, content: Iterable<Bytes> }> [multiple files]
3235 * Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
3336 * Iterable<{ path, content: PullStream<Bytes> }> [multiple files]
37+ * Iterable<{ path, content: Readable<Bytes> }> [multiple files]
3438 * AsyncIterable<Bytes> [single file]
3539 * AsyncIterable<Bloby> [multiple files]
3640 * AsyncIterable<String> [multiple files]
@@ -41,6 +45,7 @@ const globalThis = require('../globalthis')
4145 * AsyncIterable<{ path, content: Iterable<Bytes> }> [multiple files]
4246 * AsyncIterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
4347 * AsyncIterable<{ path, content: PullStream<Bytes> }> [multiple files]
48+ * AsyncIterable<{ path, content: Readable<Bytes> }> [multiple files]
4449 * PullStream<Bytes> [single file]
4550 * PullStream<Bloby> [multiple files]
4651 * PullStream<String> [multiple files]
@@ -51,6 +56,18 @@ const globalThis = require('../globalthis')
5156 * PullStream<{ path, content: Iterable<Bytes> }> [multiple files]
5257 * PullStream<{ path, content: AsyncIterable<Bytes> }> [multiple files]
5358 * 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]
5471 * ```
5572 * Into:
5673 *
@@ -82,6 +99,11 @@ module.exports = function normaliseInput (input) {
8299 } ) ( )
83100 }
84101
102+ // Readable<?>
103+ if ( isOldReadable ( input ) ) {
104+ input = upgradeOldStream ( input )
105+ }
106+
85107 // Iterable<?>
86108 if ( input [ Symbol . iterator ] ) {
87109 return ( async function * ( ) { // eslint-disable-line require-await
@@ -213,6 +235,11 @@ function toAsyncIterable (input) {
213235 return blobToAsyncGenerator ( input )
214236 }
215237
238+ // Readable<?>
239+ if ( isOldReadable ( input ) ) {
240+ input = upgradeOldStream ( input )
241+ }
242+
216243 // Iterator<?>
217244 if ( input [ Symbol . iterator ] ) {
218245 return ( async function * ( ) { // eslint-disable-line require-await
@@ -259,6 +286,14 @@ function toAsyncIterable (input) {
259286 throw errCode ( new Error ( `Unexpected input: ${ input } ` , 'ERR_UNEXPECTED_INPUT' ) )
260287}
261288
289+ function isOldReadable ( obj ) {
290+ if ( obj [ Symbol . iterator ] || obj [ Symbol . asyncIterator ] ) {
291+ return false
292+ }
293+
294+ return Boolean ( obj . readable )
295+ }
296+
262297function toBuffer ( chunk ) {
263298 return isBytes ( chunk ) ? chunk : Buffer . from ( chunk )
264299}
@@ -276,6 +311,17 @@ function isFileObject (obj) {
276311 return typeof obj === 'object' && ( obj . path || obj . content )
277312}
278313
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+
279325function blobToAsyncGenerator ( blob ) {
280326 if ( typeof blob . stream === 'function' ) {
281327 // firefox < 69 does not support blob.stream()
0 commit comments