22
33const errCode = require ( 'err-code' )
44const { Buffer } = require ( 'buffer' )
5- const pullStreamToIterable = require ( 'pull-stream-to-async-iterator' )
6- const { isSource } = require ( 'is-pull-stream' )
75const globalThis = require ( '../globalthis' )
8- const { Readable } = require ( 'stream' )
9- const Readable3 = require ( 'readable-stream' )
106
117/*
128 * Transform one of:
@@ -21,8 +17,6 @@ const Readable3 = require('readable-stream')
2117 * { path, content: Iterable<Number> } [single file]
2218 * { path, content: Iterable<Bytes> } [single file]
2319 * { path, content: AsyncIterable<Bytes> } [single file]
24- * { path, content: PullStream<Bytes> } [single file]
25- * { path, content: Readable<Bytes> } [single file]
2620 * Iterable<Number> [single file]
2721 * Iterable<Bytes> [single file]
2822 * Iterable<Bloby> [multiple files]
@@ -33,8 +27,6 @@ const Readable3 = require('readable-stream')
3327 * Iterable<{ path, content: Iterable<Number> }> [multiple files]
3428 * Iterable<{ path, content: Iterable<Bytes> }> [multiple files]
3529 * Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
36- * Iterable<{ path, content: PullStream<Bytes> }> [multiple files]
37- * Iterable<{ path, content: Readable<Bytes> }> [multiple files]
3830 * AsyncIterable<Bytes> [single file]
3931 * AsyncIterable<Bloby> [multiple files]
4032 * AsyncIterable<String> [multiple files]
@@ -44,30 +36,6 @@ const Readable3 = require('readable-stream')
4436 * AsyncIterable<{ path, content: Iterable<Number> }> [multiple files]
4537 * AsyncIterable<{ path, content: Iterable<Bytes> }> [multiple files]
4638 * AsyncIterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
47- * AsyncIterable<{ path, content: PullStream<Bytes> }> [multiple files]
48- * AsyncIterable<{ path, content: Readable<Bytes> }> [multiple files]
49- * PullStream<Bytes> [single file]
50- * PullStream<Bloby> [multiple files]
51- * PullStream<String> [multiple files]
52- * PullStream<{ path, content: Bytes }> [multiple files]
53- * PullStream<{ path, content: Bloby }> [multiple files]
54- * PullStream<{ path, content: String }> [multiple files]
55- * PullStream<{ path, content: Iterable<Number> }> [multiple files]
56- * PullStream<{ path, content: Iterable<Bytes> }> [multiple files]
57- * PullStream<{ path, content: AsyncIterable<Bytes> }> [multiple files]
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]
7139 * ```
7240 * Into:
7341 *
@@ -99,11 +67,6 @@ module.exports = function normaliseInput (input) {
9967 } ) ( )
10068 }
10169
102- // Readable<?>
103- if ( isOldReadable ( input ) ) {
104- input = upgradeOldStream ( input )
105- }
106-
10770 // Iterable<?>
10871 if ( input [ Symbol . iterator ] ) {
10972 return ( async function * ( ) { // eslint-disable-line require-await
@@ -176,37 +139,6 @@ module.exports = function normaliseInput (input) {
176139 } ) ( )
177140 }
178141
179- // PullStream<?>
180- if ( isSource ( input ) ) {
181- return ( async function * ( ) {
182- const iterator = pullStreamToIterable ( input ) [ Symbol . asyncIterator ] ( )
183- const first = await iterator . next ( )
184- if ( first . done ) return iterator
185-
186- // PullStream<Bytes>
187- if ( isBytes ( first . value ) ) {
188- yield toFileObject ( ( async function * ( ) { // eslint-disable-line require-await
189- yield first . value
190- yield * iterator
191- } ) ( ) )
192- return
193- }
194-
195- // PullStream<Bloby>
196- // PullStream<String>
197- // PullStream<{ path, content }>
198- if ( isFileObject ( first . value ) || isBloby ( first . value ) || typeof first . value === 'string' ) {
199- yield toFileObject ( first . value )
200- for await ( const obj of iterator ) {
201- yield toFileObject ( obj )
202- }
203- return
204- }
205-
206- throw errCode ( new Error ( 'Unexpected input: ' + typeof input ) , 'ERR_UNEXPECTED_INPUT' )
207- } ) ( )
208- }
209-
210142 throw errCode ( new Error ( 'Unexpected input: ' + typeof input ) , 'ERR_UNEXPECTED_INPUT' )
211143}
212144
@@ -235,11 +167,6 @@ function toAsyncIterable (input) {
235167 return blobToAsyncGenerator ( input )
236168 }
237169
238- // Readable<?>
239- if ( isOldReadable ( input ) ) {
240- input = upgradeOldStream ( input )
241- }
242-
243170 // Iterator<?>
244171 if ( input [ Symbol . iterator ] ) {
245172 return ( async function * ( ) { // eslint-disable-line require-await
@@ -278,22 +205,9 @@ function toAsyncIterable (input) {
278205 } ) ( )
279206 }
280207
281- // PullStream<Bytes>
282- if ( isSource ( input ) ) {
283- return pullStreamToIterable ( input )
284- }
285-
286208 throw errCode ( new Error ( `Unexpected input: ${ input } ` , 'ERR_UNEXPECTED_INPUT' ) )
287209}
288210
289- function isOldReadable ( obj ) {
290- if ( obj [ Symbol . iterator ] || obj [ Symbol . asyncIterator ] ) {
291- return false
292- }
293-
294- return Boolean ( obj . readable )
295- }
296-
297211function toBuffer ( chunk ) {
298212 return isBytes ( chunk ) ? chunk : Buffer . from ( chunk )
299213}
@@ -311,17 +225,6 @@ function isFileObject (obj) {
311225 return typeof obj === 'object' && ( obj . path || obj . content )
312226}
313227
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-
325228function blobToAsyncGenerator ( blob ) {
326229 if ( typeof blob . stream === 'function' ) {
327230 // firefox < 69 does not support blob.stream()
0 commit comments