File tree 3 files changed +25
-1
lines changed
3 files changed +25
-1
lines changed Original file line number Diff line number Diff line change @@ -14,6 +14,12 @@ module.exports = input => {
14
14
15
15
function prepare ( value ) {
16
16
input = value ;
17
+ if (
18
+ input instanceof ArrayBuffer ||
19
+ ( ArrayBuffer . isView ( input ) && ! Buffer . isBuffer ( input ) )
20
+ ) {
21
+ input = Buffer . from ( input ) ;
22
+ }
17
23
promise = pIsPromise ( input ) ? input : null ;
18
24
// We don't iterate on strings and buffers since slicing them is ~7x faster
19
25
const shouldIterate = ! promise && input [ Symbol . iterator ] && typeof input !== 'string' && ! Buffer . isBuffer ( input ) ;
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ intoStream('unicorn').pipe(process.stdout);
26
26
27
27
### intoStream(input)
28
28
29
- Type: ` Buffer ` ` string ` ` Iterable<Buffer|string> ` ` Promise ` <br >
29
+ Type: ` Buffer ` ` TypedArray ` ` ArrayBuffer ` ` string ` ` Iterable<Buffer|string> ` ` Promise ` <br >
30
30
Returns: [ Readable stream] ( https://nodejs.org/api/stream.html#stream_class_stream_readable )
31
31
32
32
Adheres to the requested chunk size, except for ` array ` where each element will be a chunk.
Original file line number Diff line number Diff line change @@ -24,6 +24,24 @@ test('buffer', async t => {
24
24
t . true ( ( await getStream . buffer ( m ( f ) ) ) . equals ( f ) ) ;
25
25
} ) ;
26
26
27
+ test ( 'ArrayBuffer' , async t => {
28
+ const f = Buffer . from ( fixture ) ;
29
+ const view = new Uint8Array ( f . length ) ;
30
+ for ( let i = 0 ; i < f . length ; i ++ ) {
31
+ view [ i ] = f [ i ] ;
32
+ }
33
+ t . true ( ( await getStream . buffer ( m ( view . buffer ) ) ) . equals ( f ) ) ;
34
+ } ) ;
35
+
36
+ test ( 'ArrayBuffer view' , async t => {
37
+ const f = Buffer . from ( fixture ) ;
38
+ const view = new Uint8Array ( f . length ) ;
39
+ for ( let i = 0 ; i < f . length ; i ++ ) {
40
+ view [ i ] = f [ i ] ;
41
+ }
42
+ t . true ( ( await getStream . buffer ( m ( view ) ) ) . equals ( f ) ) ;
43
+ } ) ;
44
+
27
45
test ( 'array' , async t => {
28
46
t . is ( await getStream ( m ( fixture . split ( '' ) ) ) , fixture ) ;
29
47
} ) ;
You can’t perform that action at this time.
0 commit comments