2
2
3
3
const errCode = require ( 'err-code' )
4
4
const { Buffer } = require ( 'buffer' )
5
- const pullStreamToIterable = require ( 'pull-stream-to-async-iterator' )
6
- const { isSource } = require ( 'is-pull-stream' )
7
5
const globalThis = require ( '../globalthis' )
8
- const { Readable } = require ( 'stream' )
9
- const Readable3 = require ( 'readable-stream' )
10
6
11
7
/*
12
8
* Transform one of:
@@ -21,8 +17,6 @@ const Readable3 = require('readable-stream')
21
17
* { path, content: Iterable<Number> } [single file]
22
18
* { path, content: Iterable<Bytes> } [single file]
23
19
* { path, content: AsyncIterable<Bytes> } [single file]
24
- * { path, content: PullStream<Bytes> } [single file]
25
- * { path, content: Readable<Bytes> } [single file]
26
20
* Iterable<Number> [single file]
27
21
* Iterable<Bytes> [single file]
28
22
* Iterable<Bloby> [multiple files]
@@ -33,8 +27,6 @@ const Readable3 = require('readable-stream')
33
27
* Iterable<{ path, content: Iterable<Number> }> [multiple files]
34
28
* Iterable<{ path, content: Iterable<Bytes> }> [multiple files]
35
29
* Iterable<{ path, content: AsyncIterable<Bytes> }> [multiple files]
36
- * Iterable<{ path, content: PullStream<Bytes> }> [multiple files]
37
- * Iterable<{ path, content: Readable<Bytes> }> [multiple files]
38
30
* AsyncIterable<Bytes> [single file]
39
31
* AsyncIterable<Bloby> [multiple files]
40
32
* AsyncIterable<String> [multiple files]
@@ -44,30 +36,6 @@ const Readable3 = require('readable-stream')
44
36
* AsyncIterable<{ path, content: Iterable<Number> }> [multiple files]
45
37
* AsyncIterable<{ path, content: Iterable<Bytes> }> [multiple files]
46
38
* 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]
71
39
* ```
72
40
* Into:
73
41
*
@@ -99,11 +67,6 @@ module.exports = function normaliseInput (input) {
99
67
} ) ( )
100
68
}
101
69
102
- // Readable<?>
103
- if ( isOldReadable ( input ) ) {
104
- input = upgradeOldStream ( input )
105
- }
106
-
107
70
// Iterable<?>
108
71
if ( input [ Symbol . iterator ] ) {
109
72
return ( async function * ( ) { // eslint-disable-line require-await
@@ -176,37 +139,6 @@ module.exports = function normaliseInput (input) {
176
139
} ) ( )
177
140
}
178
141
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
-
210
142
throw errCode ( new Error ( 'Unexpected input: ' + typeof input ) , 'ERR_UNEXPECTED_INPUT' )
211
143
}
212
144
@@ -235,11 +167,6 @@ function toAsyncIterable (input) {
235
167
return blobToAsyncGenerator ( input )
236
168
}
237
169
238
- // Readable<?>
239
- if ( isOldReadable ( input ) ) {
240
- input = upgradeOldStream ( input )
241
- }
242
-
243
170
// Iterator<?>
244
171
if ( input [ Symbol . iterator ] ) {
245
172
return ( async function * ( ) { // eslint-disable-line require-await
@@ -278,22 +205,9 @@ function toAsyncIterable (input) {
278
205
} ) ( )
279
206
}
280
207
281
- // PullStream<Bytes>
282
- if ( isSource ( input ) ) {
283
- return pullStreamToIterable ( input )
284
- }
285
-
286
208
throw errCode ( new Error ( `Unexpected input: ${ input } ` , 'ERR_UNEXPECTED_INPUT' ) )
287
209
}
288
210
289
- function isOldReadable ( obj ) {
290
- if ( obj [ Symbol . iterator ] || obj [ Symbol . asyncIterator ] ) {
291
- return false
292
- }
293
-
294
- return Boolean ( obj . readable )
295
- }
296
-
297
211
function toBuffer ( chunk ) {
298
212
return isBytes ( chunk ) ? chunk : Buffer . from ( chunk )
299
213
}
@@ -311,17 +225,6 @@ function isFileObject (obj) {
311
225
return typeof obj === 'object' && ( obj . path || obj . content )
312
226
}
313
227
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
-
325
228
function blobToAsyncGenerator ( blob ) {
326
229
if ( typeof blob . stream === 'function' ) {
327
230
// firefox < 69 does not support blob.stream()
0 commit comments