11import { ReactNativeBlobUtilResponseInfo , ReactNativeBlobUtilStream } from "../types" ;
22import fs from "../fs" ;
3- import polyfill from "../polyfill" ;
3+ import Blob from "../polyfill/Blob" ;
4+ import ReactNativeBlobUtilSession from "./ReactNativeBlobUtilSession" ;
5+ import URIUtil from "../utils/uri" ;
46
57/**
68 * ReactNativeBlobUtil response object class.
@@ -55,18 +57,17 @@ export class FetchBlobResponse {
5557 * @return {Promise<Blob> } Return a promise resolves Blob object.
5658 */
5759 this . blob = ( ) : Promise < Blob > => {
58- let Blob = polyfill . Blob ;
5960 let cType = info . headers [ 'Content-Type' ] || info . headers [ 'content-type' ] ;
6061 return new Promise ( ( resolve , reject ) => {
6162 switch ( this . type ) {
6263 case 'base64' :
6364 Blob . build ( this . data , { type : cType + ';BASE64' } ) . then ( resolve ) ;
6465 break ;
6566 case 'path' :
66- polyfill . Blob . build ( wrap ( this . data ) , { type : cType } ) . then ( resolve ) ;
67+ Blob . build ( URIUtil . wrap ( this . data ) , { type : cType } ) . then ( resolve ) ;
6768 break ;
6869 default :
69- polyfill . Blob . build ( this . data , { type : 'text/plain' } ) . then ( resolve ) ;
70+ Blob . build ( this . data , { type : 'text/plain' } ) . then ( resolve ) ;
7071 break ;
7172 }
7273 } ) ;
@@ -76,7 +77,6 @@ export class FetchBlobResponse {
7677 * @return {string } Decoded base64 string.
7778 */
7879 this . text = ( ) : string | Promise < any > => {
79- let res = this . data ;
8080 switch ( this . type ) {
8181 case 'base64' :
8282 return base64 . decode ( this . data ) ;
@@ -123,7 +123,7 @@ export class FetchBlobResponse {
123123 let path = this . path ( ) ;
124124 if ( ! path || this . type !== 'path' )
125125 return ;
126- return unlink ( path ) ;
126+ return fs . unlink ( path ) ;
127127 } ;
128128 /**
129129 * get path of response temp file
@@ -137,7 +137,7 @@ export class FetchBlobResponse {
137137
138138 this . session = ( name : string ) : ReactNativeBlobUtilSession | null = > {
139139 if ( this . type === 'path' )
140- return session ( name ) . add ( this . data ) ;
140+ return fs . session ( name ) . add ( this . data ) ;
141141 else {
142142 console . warn ( 'only file paths can be add into session.' ) ;
143143 return null ;
@@ -150,7 +150,7 @@ export class FetchBlobResponse {
150150 */
151151 this . readStream = ( encoding : 'base64' | 'utf8' | 'ascii' ) : ReactNativeBlobUtilStream | null = > {
152152 if ( this . type === 'path' ) {
153- return readStream ( this . data , encoding ) ;
153+ return fs . readStream ( this . data , encoding ) ;
154154 }
155155 else {
156156 console . warn ( 'ReactNativeBlobUtil' , 'this response data does not contains any available stream' ) ;
@@ -165,7 +165,7 @@ export class FetchBlobResponse {
165165 */
166166 this . readFile = ( encoding : 'base64' | 'utf8' | 'ascii' ) => {
167167 if ( this . type === 'path' ) {
168- return readFile ( this . data , encoding ) ;
168+ return fs . readFile ( this . data , encoding ) ;
169169 }
170170 else {
171171 console . warn ( 'ReactNativeBlobUtil' , 'this response does not contains a readable file' ) ;
0 commit comments