1
1
import { ReactNativeBlobUtilResponseInfo , ReactNativeBlobUtilStream } from "../types" ;
2
2
import 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" ;
4
6
5
7
/**
6
8
* ReactNativeBlobUtil response object class.
@@ -55,18 +57,17 @@ export class FetchBlobResponse {
55
57
* @return {Promise<Blob> } Return a promise resolves Blob object.
56
58
*/
57
59
this . blob = ( ) : Promise < Blob > => {
58
- let Blob = polyfill . Blob ;
59
60
let cType = info . headers [ 'Content-Type' ] || info . headers [ 'content-type' ] ;
60
61
return new Promise ( ( resolve , reject ) => {
61
62
switch ( this . type ) {
62
63
case 'base64' :
63
64
Blob . build ( this . data , { type : cType + ';BASE64' } ) . then ( resolve ) ;
64
65
break ;
65
66
case 'path' :
66
- polyfill . Blob . build ( wrap ( this . data ) , { type : cType } ) . then ( resolve ) ;
67
+ Blob . build ( URIUtil . wrap ( this . data ) , { type : cType } ) . then ( resolve ) ;
67
68
break ;
68
69
default :
69
- polyfill . Blob . build ( this . data , { type : 'text/plain' } ) . then ( resolve ) ;
70
+ Blob . build ( this . data , { type : 'text/plain' } ) . then ( resolve ) ;
70
71
break ;
71
72
}
72
73
} ) ;
@@ -76,7 +77,6 @@ export class FetchBlobResponse {
76
77
* @return {string } Decoded base64 string.
77
78
*/
78
79
this . text = ( ) : string | Promise < any > => {
79
- let res = this . data ;
80
80
switch ( this . type ) {
81
81
case 'base64' :
82
82
return base64 . decode ( this . data ) ;
@@ -123,7 +123,7 @@ export class FetchBlobResponse {
123
123
let path = this . path ( ) ;
124
124
if ( ! path || this . type !== 'path' )
125
125
return ;
126
- return unlink ( path ) ;
126
+ return fs . unlink ( path ) ;
127
127
} ;
128
128
/**
129
129
* get path of response temp file
@@ -137,7 +137,7 @@ export class FetchBlobResponse {
137
137
138
138
this . session = ( name : string ) : ReactNativeBlobUtilSession | null = > {
139
139
if ( this . type === 'path' )
140
- return session ( name ) . add ( this . data ) ;
140
+ return fs . session ( name ) . add ( this . data ) ;
141
141
else {
142
142
console . warn ( 'only file paths can be add into session.' ) ;
143
143
return null ;
@@ -150,7 +150,7 @@ export class FetchBlobResponse {
150
150
*/
151
151
this . readStream = ( encoding : 'base64' | 'utf8' | 'ascii' ) : ReactNativeBlobUtilStream | null = > {
152
152
if ( this . type === 'path' ) {
153
- return readStream ( this . data , encoding ) ;
153
+ return fs . readStream ( this . data , encoding ) ;
154
154
}
155
155
else {
156
156
console . warn ( 'ReactNativeBlobUtil' , 'this response data does not contains any available stream' ) ;
@@ -165,7 +165,7 @@ export class FetchBlobResponse {
165
165
*/
166
166
this . readFile = ( encoding : 'base64' | 'utf8' | 'ascii' ) => {
167
167
if ( this . type === 'path' ) {
168
- return readFile ( this . data , encoding ) ;
168
+ return fs . readFile ( this . data , encoding ) ;
169
169
}
170
170
else {
171
171
console . warn ( 'ReactNativeBlobUtil' , 'this response does not contains a readable file' ) ;
0 commit comments