JSPM

@tanker/file-ponyfill

2.5.0-beta1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5001
  • Score
    100M100P100Q136665F
  • License Apache-2.0

A cross-browser ponyfill for File with a working constructor

Package Exports

  • @tanker/file-ponyfill

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-ponyfill) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

License NPM Package Minified Size

A cross-browser ponyfill for File

Why

A common issue with the JavaScript File class is the lack of a constructor in some browsers:

new File(['Hi!'], 'file.txt'); // will throw in Edge and Internet Explorer

Using feature detection, this package will either expose a File ponyfill in browsers lacking a proper constructor, or the native File class in others.

Usage

You can safely use this package as a drop-in replacement for the native File class in all browsers, e.g.:

import FilePonyfill from '@tanker/file-ponyfill';

// Get bits from whatever method you want, using fetch() as an example
const response = await fetch('https://your.server.com/path/to/a/report.pdf');
const bits = [await response.arrayBuffer()];

// Construct a file in a cross-browser fashion
const file = new FilePonyfill(bits, 'report.pdf', { type: 'application/pdf' });

// Check what we've got
file instanceof window.Blob; // true
file instanceof window.File; // true
file instanceof FilePonyfill; // true
file.name; // 'report.pdf'
file.type; // 'application/pdf'
file.size; // the size of report.pdf

Note that the ponyfill is built using a clever class hierarchy so that instances will appear as regular File and Blob instances, which can safely be read by a FileReader and used with other APIs working with files.

License

Developped by Tanker, under the Apache-2.0 license.

Tanker's client SDKs allow for seamless integration of client-side end-to-end encryption in your application.

Tanker is available for iOS, Android, and Web apps.

Read the documentation to get started.

Go to tanker.io for more information about Tanker.