55
66import  './streams.cjs' 
77
8- /** @typedef  {import('buffer').Blob } NodeBlob} */ 
9- 
108// 64 KiB (same size chrome slice theirs blob into Uint8array's) 
119const  POOL_SIZE  =  65536 
1210
13- /** @param  {(Blob | NodeBlob |  Uint8Array)[] } parts */ 
11+ /** @param  {(Blob | Uint8Array)[] } parts */ 
1412async  function  *  toIterator  ( parts ,  clone  =  true )  { 
1513  for  ( const  part  of  parts )  { 
1614    if  ( 'stream'  in  part )  { 
17-       yield  *  part . stream ( ) 
15+       yield  *  ( /**  @type  { AsyncIterableIterator<Uint8Array> } */   ( part . stream ( ) ) ) 
1816    }  else  if  ( ArrayBuffer . isView ( part ) )  { 
1917      if  ( clone )  { 
2018        let  position  =  part . byteOffset 
@@ -28,17 +26,16 @@ async function * toIterator (parts, clone = true) {
2826      }  else  { 
2927        yield  part 
3028      } 
29+     /* c8 ignore next 10 */ 
3130    }  else  { 
32-       /* c8 ignore start */ 
3331      // For blobs that have arrayBuffer but no stream method (nodes buffer.Blob) 
34-       let  position  =  0 
35-       while  ( position  !==  part . size )  { 
36-         const  chunk  =  part . slice ( position ,  Math . min ( part . size ,  position  +  POOL_SIZE ) ) 
32+       let  position  =  0 ,   b   =   ( /**  @type  { Blob } */   ( part ) ) 
33+       while  ( position  !==  b . size )  { 
34+         const  chunk  =  b . slice ( position ,  Math . min ( b . size ,  position  +  POOL_SIZE ) ) 
3735        const  buffer  =  await  chunk . arrayBuffer ( ) 
3836        position  +=  buffer . byteLength 
3937        yield  new  Uint8Array ( buffer ) 
4038      } 
41-       /* c8 ignore end */ 
4239    } 
4340  } 
4441} 
@@ -48,14 +45,15 @@ const _Blob = class Blob {
4845  #parts =  [ ] 
4946  #type =  '' 
5047  #size =  0 
48+   #endings =  'transparent' 
5149
5250  /** 
5351   * The Blob() constructor returns a new Blob object. The content 
5452   * of the blob consists of the concatenation of the values given 
5553   * in the parameter array. 
5654   * 
5755   * @param  {* } blobParts 
58-    * @param  {{ type?: string } } [options] 
56+    * @param  {{ type?: string, endings?: string  } } [options] 
5957   */ 
6058  constructor  ( blobParts  =  [ ] ,  options  =  { } )  { 
6159    if  ( typeof  blobParts  !==  'object'  ||  blobParts  ===  null )  { 
@@ -82,15 +80,15 @@ const _Blob = class Blob {
8280      }  else  if  ( element  instanceof  Blob )  { 
8381        part  =  element 
8482      }  else  { 
85-         part  =  encoder . encode ( element ) 
83+         part  =  encoder . encode ( ` ${ element } ` ) 
8684      } 
8785
8886      this . #size +=  ArrayBuffer . isView ( part )  ? part . byteLength  : part . size 
8987      this . #parts. push ( part ) 
9088    } 
9189
90+     this . #endings =  `${ options . endings  ===  undefined  ? 'transparent'  : options . endings }  
9291    const  type  =  options . type  ===  undefined  ? ''  : String ( options . type ) 
93- 
9492    this . #type =  / ^ [ \x20 - \x7E ] * $ / . test ( type )  ? type  : '' 
9593  } 
9694
@@ -156,6 +154,7 @@ const _Blob = class Blob {
156154    const  it  =  toIterator ( this . #parts,  true ) 
157155
158156    return  new  globalThis . ReadableStream ( { 
157+       // @ts -ignore 
159158      type : 'bytes' , 
160159      async  pull  ( ctrl )  { 
161160        const  chunk  =  await  it . next ( ) 
0 commit comments