New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

drive-fsa

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

drive-fsa

Wrapper for the File System Access API

latest
Source
npmnpm
Version
1.0.8
Version published
Weekly downloads
1
-75%
Maintainers
0
Weekly downloads
 
Created
Source

Drive FSA

A simple wrapper to use browser File System Access API in a more convenient way.

Installation

npm install drive-fsa

createDrive

Helper function to create a drive object from a directory handle

import { createDrive } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

const drive = createDrive(handle);

// list all files in the root directory
const entries = await drive.list('/');

// list all files in a subdirectory
const entries = await drive.list('/subdir1/subdir2');

// get individual file
const entry = await drive.get('/file.txt');

// read file, returns a Uint8Array
const uint8 = await drive.read('/file.txt');

// read file as text
const text = await drive.read('/file.txt', { contentType: 'text' });

// read file as json 
const json = await drive.read('/file.txt', { contentType: 'json' });

// write to file Uint8Array
await drive.write('/file.txt', new TextEncoder().encode('Hello, World!'));

// write to file text 
await drive.write('/file.txt', 'Hello, World!', { contentType: 'text' });

// write to file json 
await drive.write('/file.txt', { hello: 'world' }, { contentType: 'json' });

// delete file 
await drive.destroy('/file.txt');

findEntry

Get an entry by path

import { findEntry } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

const entry = await findEntry(handle, '/file.txt');

listEntries

List all entries in a directory

import { listEntries } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

const entries = await listEntries(handle, '/');

readEntry

Read the content of a file

import { readEntry } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

const data = await readEntry(handle, '/file.txt'); // Promise<Uint8Array>

Use options to specify the content type

readEntry(handle, '/file.txt', { contentType: 'text' }); // Promise<string>
readEntry(handle, '/file.txt', { contentType: 'json' }); // Promise<Record<string, any>>
readEntry(handle, '/file.txt', { contentType: 'uint8array' }); // Promise<Uint8Array>

makeDirectoryEntry

Create a directory

import { makeDirectoryEntry } from 'drive-fsa'; 

const handle = await window.showDirectoryPicker();

await makeDirectoryEntry(handle, '/subdir1/subdir2');

Create a directory recursively

makeDirectoryEntry(handle, '/subdir1/subdir2', { recursive: true });

writeEntry

Write to a file

import { writeEntry, encode } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

await writeEntry(handle, '/file.txt', encode('Hello, World!'));

Use options to specify the content type

writeEntry(handle, '/file.txt', 'Hello, World!', { contentType: 'text' });
writeEntry(handle, '/file.txt', { hello: 'world' }, { contentType: 'json' });
writeEntry(handle, '/file.txt', new Uint8Array([1, 2, 3]), { contentType: 'uint8array' });

Recursive write

writeEntry(handle, '/subdir1/subdir2/file.txt', 'Hello, World!', { recursive: true });

destroyEntry

Delete a file or a directory

import { destroyEntry } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

await destroyEntry(handle, '/file.txt');

findHandle

Get a handle by path

Can be used to get a deep handle of a file or a directory

import { findHandle } from 'drive-fsa';

const handle = await window.showDirectoryPicker();

const fileHandle = await findHandle(handle, '/file.txt');

const dirHandle = await findHandle(handle, '/subdir1/subdir2');

Keywords

fsa

FAQs

Package last updated on 16 Dec 2024

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