Package Exports
- @tanker/file-reader
- @tanker/file-reader/dist/browser/index.js
- @tanker/file-reader/dist/es/index.js
- @tanker/file-reader/dist/node/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@tanker/file-reader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
A promisified FileReader for browsers
A promisified FileReader implementation very similar to the browser's FileReader API, with a few differences:
- the File or Blob instance is given at construction time;
- all
readAs...methods don't take a Blob or File instance as first argument anymore; - all
readAs...methods return a Promise that can be awaited; - reading in chunks is easy as:
- you just need to await the next chunk (no event / callback API anymore);
- the current reading position is automatically tracked.
Usage
import FileReader from '@tanker/file-reader';
// Retrieve a file or blob somehow
const file = new File(
['The quick brown fox jumps over the lazy dog'],
'fox.txt',
{ type: 'plain/text' }
);
// Create your file reader
const reader = new FileReader(file);
// Read the whole file
const text = await reader.readAsText('UTF-8');
const dataUrl = await reader.readAsDataURL();
const arrayBuffer = await reader.readAsArrayBuffer();
// Or read binary chunks (ArrayBuffer)
const chunkSize = 8; // bytes
let chunk;
do {
chunk = await reader.readAsArrayBuffer(chunkSize);
// do something with the chunk
} while (chunk.byteLength > 0);About Tanker
This package is a dependency of the Tanker client SDKs for end-to-end encryption:
- @tanker/client-browser for Web applications
- @tanker/client-node for Node.js client applications
Read the documentation to get started.