browser-nativefs
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "browser-nativefs", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Native File System API with legacy fallback in the browser.", | ||
@@ -20,6 +20,6 @@ "browser": "./dist/nativefs.mjs", | ||
"keywords": [ | ||
"Native", | ||
"File", | ||
"System", | ||
"API" | ||
"native file system", | ||
"native file system api", | ||
"native fs", | ||
"nativefs" | ||
], | ||
@@ -26,0 +26,0 @@ "files": [ |
@@ -1,2 +0,53 @@ | ||
# browser-nativefs | ||
Native File System API with legacy fallback in the browser | ||
# Browser-NativeFS | ||
Use the [Native File System API](https://wicg.github.io/native-file-system/) | ||
with legacy fallback in the browser. | ||
## Usage | ||
```bash | ||
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. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16287
54