Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@tanker/file-reader

Package Overview
Dependencies
Maintainers
4
Versions
271
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tanker/file-reader

A promisified FileReader for browsers

latest
Source
npmnpm
Version
4.3.0
Version published
Weekly downloads
5K
-24.83%
Maintainers
4
Weekly downloads
 
Created
Source

A promisified FileReader for browsers

License NPM Package Minified Size

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:

Read the documentation to get started.

Keywords

filereader

FAQs

Package last updated on 06 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts