Research
Security News
Threat Actor Exposes Playbook for Exploiting npm to Build Blockchain-Powered Botnets
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
browser-fs-access
Advanced tools
This module allows you to easily use the
File System Access API on supporting browsers,
with a transparent fallback to the <input type="file">
and <a download>
legacy methods.
This library is a ponyfill.
Read more on the background of this module in my post Progressive Enhancement In the Age of Fugu APIs.
See the library in action: https://browser-fs-access.glitch.me/.
You can install the module with npm.
npm install --save browser-fs-access
The module feature-detects support for the File System Access API and only loads the actually relevant code.
// The imported methods will use the File System
// Access API or a fallback implementation.
import {
fileOpen,
directoryOpen,
fileSave,
supported,
} from 'https://unpkg.com/browser-fs-access';
(async () => {
if (supported) {
console.log('Using the File System Access API.');
} else {
console.log('Using the fallback implementation.');
}
// Open a file.
const blob = await fileOpen({
mimeTypes: ['image/*'],
});
// Open multiple files.
const blobs = await fileOpen({
mimeTypes: ['image/*'],
multiple: true,
});
// Open all files in a directory,
// recursively including subdirectories.
const blobsInDirectory = await directoryOpen({
recursive: true,
});
// Save a file.
await fileSave(blob, {
fileName: 'Untitled.png',
extensions: ['.png'],
});
})();
// Options are optional.
const options = {
// List of allowed MIME types, defaults to `*/*`.
mimeTypes: ['image/*'],
// List of allowed file extensions (with leading '.'), defaults to `''`.
extensions: ['.png', '.jpg', '.jpeg', '.webp'],
// Set to `true` for allowing multiple files, defaults to `false`.
multiple: true,
// Textual description for file dialog , defaults to `''`.
description: 'Image files',
};
const blobs = await fileOpen(options);
// Options are optional.
const options = {
// Set to `true` to recursively open files in all subdirectories,
// defaults to `false`.
recursive: true,
};
const blobs = await directoryOpen(options);
The module also polyfills a webkitRelativePath
property on returned files in a consistent way, regardless of the underlying implementation.
// Options are optional.
const options = {
// Suggested file name to use, defaults to `''`.
fileName: 'Untitled.txt',
// Suggested file extensions (with leading '.'), defaults to `''`.
extensions: ['.txt'],
};
// Optional file handle to save back to an existing file.
// This will only work with the File System Access API.
// Get a `FileHandle` from the `handle` property of the `Blob`
// you receive from `fileOpen()` (this is non-standard).
const existingHandle = previouslyOpenedBlob.handle;
// Optional flag to determine whether to throw (rather than open a new file
// save dialog) when `existingHandle` is no longer good, for example, because
// the underlying file was deleted. Defaults to `false`.
const throwIfExistingHandleNotGood = true;
await fileSave(someBlob, options, existingHandle, throwIfExistingHandleNotGood);
The File System Access API supports exceptions, so apps can throw when problems occur (permissions
not granted, out of disk space,…), or when the user cancels the dialog. The legacy methods,
unfortunately, do not support exceptions (albeit there is an
HTML issue open for this request). If your app depends
on exceptions, see the file
index.d.ts
for the
documentation of the setupLegacyCleanupAndRejection
parameter.
You can see the module in action in the Excalidraw drawing app.
A similar, but more extensive library called native-file-system-adapter is provided by @jimmywarting.
Thanks to @developit
for improving the dynamic module loading
and @dwelle for the helpful feedback,
issue reports, and the Windows build fix.
Directory operations were made consistent regarding webkitRelativePath
and parallelized and sped up significantly by
@RReverser.
The TypeScript type annotations were initially provided by
@nanaian.
Dealing correctly with cross-origin iframes was contributed by
@nikhilbghodke and
@kbariotis.
The exception handling of the legacy methods was contributed by
@jmrog.
Apache 2.0.
This is not an official Google product.
FAQs
File System Access API with legacy fallback in the browser.
The npm package browser-fs-access receives a total of 46,983 weekly downloads. As such, browser-fs-access popularity was classified as popular.
We found that browser-fs-access demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Research
Security News
A threat actor's playbook for exploiting the npm ecosystem was exposed on the dark web, detailing how to build a blockchain-powered botnet.
Security News
NVD’s backlog surpasses 20,000 CVEs as analysis slows and NIST announces new system updates to address ongoing delays.
Security News
Research
A malicious npm package disguised as a WhatsApp client is exploiting authentication flows with a remote kill switch to exfiltrate data and destroy files.