Browse Source

Add readBlob method to Blob for more easier content access

Ben Hsieh 8 years ago
parent
commit
0896254bee
1 changed files with 13 additions and 0 deletions
  1. 13
    0
      src/polyfill/Blob.js

+ 13
- 0
src/polyfill/Blob.js View File

196
     if(this._closed)
196
     if(this._closed)
197
       throw 'Blob has been released.'
197
       throw 'Blob has been released.'
198
     log.verbose('slice called', start, end, encoding)
198
     log.verbose('slice called', start, end, encoding)
199
+    console.warn('RNFB#Blob.slice() is not implemented yet, to read Blob content, use Blob.readBlob(encoding:string) instead.')
199
     // TODO : fs.slice
200
     // TODO : fs.slice
200
     // return fs.slice(this.cacheName, getBlobName(), contentType, start, end)
201
     // return fs.slice(this.cacheName, getBlobName(), contentType, start, end)
201
   }
202
   }
202
 
203
 
204
+  /**
205
+   * Read data of the Blob object, this is not standard method.
206
+   * @nonstandard
207
+   * @param  {string} encoding Read data with encoding
208
+   * @return {Promise}
209
+   */
210
+  readBlob(encoding:string):Promise<any> {
211
+    if(this._closed)
212
+      throw 'Blob has been released.'
213
+    return fs.readFile(this._ref, encoding || 'utf8')
214
+  }
215
+
203
   /**
216
   /**
204
    * Release the resource of the Blob object.
217
    * Release the resource of the Blob object.
205
    * @nonstandard
218
    * @nonstandard