@@ -2,7 +2,10 @@ import { isStorageError } from '../lib/errors'
22import  {  DownloadResult  }  from  '../lib/types' 
33import  StreamDownloadBuilder  from  './StreamDownloadBuilder' 
44
5- export  default  class  BlobDownloadBuilder  implements  PromiseLike < DownloadResult < Blob > >  { 
5+ export  default  class  BlobDownloadBuilder  implements  Promise < DownloadResult < Blob > >  { 
6+   readonly  [ Symbol . toStringTag ] : string  =  'BlobDownloadBuilder' 
7+   private  promise : Promise < DownloadResult < Blob > >  |  null  =  null 
8+ 
69  constructor ( 
710    private  downloadFn : ( )  =>  Promise < Response > , 
811    private  shouldThrowOnError : boolean 
@@ -16,7 +19,24 @@ export default class BlobDownloadBuilder implements PromiseLike<DownloadResult<B
1619    onfulfilled ?: ( ( value : DownloadResult < Blob > )  =>  TResult1  |  PromiseLike < TResult1 > )  |  null , 
1720    onrejected ?: ( ( reason : any )  =>  TResult2  |  PromiseLike < TResult2 > )  |  null 
1821  ) : Promise < TResult1  |  TResult2 >  { 
19-     return  this . execute ( ) . then ( onfulfilled ,  onrejected ) 
22+     return  this . getPromise ( ) . then ( onfulfilled ,  onrejected ) 
23+   } 
24+ 
25+   catch < TResult  =  never > ( 
26+     onrejected ?: ( ( reason : any )  =>  TResult  |  PromiseLike < TResult > )  |  null 
27+   ) : Promise < DownloadResult < Blob >  |  TResult >  { 
28+     return  this . getPromise ( ) . catch ( onrejected ) 
29+   } 
30+ 
31+   finally ( onfinally ?: ( ( )  =>  void )  |  null ) : Promise < DownloadResult < Blob > >  { 
32+     return  this . getPromise ( ) . finally ( onfinally ) 
33+   } 
34+ 
35+   private  getPromise ( ) : Promise < DownloadResult < Blob > >  { 
36+     if  ( ! this . promise )  { 
37+       this . promise  =  this . execute ( ) 
38+     } 
39+     return  this . promise 
2040  } 
2141
2242  private  async  execute ( ) : Promise < DownloadResult < Blob > >  { 
0 commit comments