https://github.com/developit/browser-nativefs
Native File System API with legacy fallback in the browser
https://github.com/developit/browser-nativefs
Last synced: 9 months ago
JSON representation
Native File System API with legacy fallback in the browser
- Host: GitHub
- URL: https://github.com/developit/browser-nativefs
- Owner: developit
- License: apache-2.0
- Created: 2020-01-23T15:22:59.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-01-23T15:39:02.000Z (almost 6 years ago)
- Last Synced: 2025-04-10T11:16:05.477Z (9 months ago)
- Homepage: https://browser-nativefs.glitch.me/
- Size: 46.9 KB
- Stars: 8
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Browser-NativeFS
This module allows you to either use the
[Native File System API](https://wicg.github.io/native-file-system/) on supporting browsers,
with a transparent fallback to the `` and `` legacy methods.
## Usage
The module feature-detects support for the Native File System API and
only loads the actually relevant code.
```js
import {
fileOpenPromise,
fileSavePromise,
} from 'https://unpkg.com/browser-nativefs';
(async () => {
// This dynamically either loads the Native File System API
// or the legacy module.
const fileOpen = (await fileOpenPromise).default;
const fileSave = (await fileSavePromise).default;
// Open a file.
const blob = await fileOpen({mimeTypes: ['image/*']});
// Open multiple files
const blobs = await fileOpen({mimeTypes: ['image/*'], multiple: true});
// Save a file.
await fileSave(blob, {fileName: 'Untitled.png'});
})();
```
## API
```js
const options = {
mimeTypes: ['image/*'],
extensions: ['png', 'jpg', 'jpeg', 'webp'],
multiple: true,
description: 'Image files',
};
const blobs = await fileOpen(options);
```
```js
const options = {
fileName: 'Untitled.txt',
};
await fileSave(someBlob, options);
```
## License
Apache 2.0.