ebidel / idb.filesystem.js

HTML5 Filesystem API polyfill using IndexedDB
https://www.npmjs.com/package/idb.filesystem.js
Other
487 stars 46 forks source link

Reading files doesn't work in firefox #43

Open stevenxxiu opened 7 years ago

stevenxxiu commented 7 years ago

new FileReader().readAsArrayBuffer(file) doesn't work, and will show the error: TypeError: Argument 1 of FileReader.readAsArrayBuffer does not implement interface Blob..

A work-around is new FileReader().readAsArrayBuffer(this.recorder.file.file_.blob_) but I'm guessing this is incompatible with real filesystem implementations.

It will work if File is made to inherit from the Blob class.

ebidel commented 7 years ago

File is a Blob-like interface, so it already does inherit. This has been supported for a while: https://developer.mozilla.org/en-US/docs/Web/API/FileReader/readAsArrayBuffer

What version of FF are you using? The following works for me:

http://jsbin.com/fanahoxami/edit?html,output

<script>
  const reader = new FileReader();
  const f = new Blob(['abc'], {type: 'text/plain'});
  reader.onload = e => {
    console.log(e.target.result);
  };
  reader.readAsArrayBuffer(f);
</script>