Socket
Socket
Sign inDemoInstall

browser-nativefs

Package Overview
Dependencies
0
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

browser-nativefs


Version published
Maintainers
1
Created

Readme

Source

Browser-NativeFS

Use the Native File System API with legacy fallback in the browser.

Usage

import {
  fileOpenPromise,
  fileSavePromise,
  imageToBlob
} from 'https://unpkg.com/browser-nativefs';

(async () => {
  const fileOpen = (await fileOpenPromise).default;
  const fileSave = (await fileSavePromise).default;

  const openButton = document.querySelector('#open');
  const saveButton = document.querySelector('#save');

  openButton.addEventListener('click', async (e) => {
    try {
      const blob = await fileOpen({mimeTypes: ['image/*']});
      const img = document.createElement('img');
      img.src = URL.createObjectURL(blob);
      document.body.append(img);
    } catch (err) {
      if (err.name !== 'AbortError') {
        console.error(err);
      }
    }
  });

  saveButton.addEventListener('click', async (e) => {
    const blob = await imageToBlob(document.querySelector('img'));
    try {
      await fileSave(blob, {fileName: 'Untitled.png'});
    } catch (err) {
      if (err.name !== 'AbortError') {
        console.error(err);
      }
    }
  });

  openButton.disabled = false;
  saveButton.disabled = false;
})();

License

Apache 2.0.

Keywords

FAQs

Last updated on 21 Jan 2020

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc