# fatfs-wasm

> High level bindings over a WASM port of FatFS by ChaN

Latest version **4.0.0** (published 2026-06-15) · MIT license · 0 weekly downloads

## Install

```sh
npm install fatfs-wasm
pnpm add fatfs-wasm
yarn add fatfs-wasm
bun add fatfs-wasm
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 4.0.0 |
| Published | 2026-06-15 |
| First published | 2024-09-29 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 306.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | parkertomatoes |
| Maintainers | parkertomatoes |

## Links

- npm: https://www.npmjs.com/package/fatfs-wasm
- npm.io page: https://npm.io/package/fatfs-wasm

## Recent versions

- 4.0.0 (latest) — 2026-06-15
- 3.0.7 — 2024-12-14
- 3.0.6 — 2024-12-14
- 3.0.5 — 2024-12-09
- 3.0.4 — 2024-12-09
- 3.0.3 — 2024-12-01
- 3.0.2 — 2024-12-01
- 3.0.1 — 2024-12-01
- 3.0.0 — 2024-12-01
- 2.0.2 — 2024-10-16
- 2.0.1 — 2024-10-10
- 2.0.0 — 2024-10-09
- 1.0.0 — 2024-09-29

## README

# Overview
fatfs-wasm is a Javascript/Typescript FAT filesystem driver for in-memory images. It provides an intuitive API for reading and writing files and data in FAT images. Under the hood, it is powered by the popular FatFS C library by CHaN, compiled to WebAssembly.

Features:
 * Javascript-friendly abstractions over FatFS's API
 * Read, write, rename, stat, chmod, and delete files
 * Create, iterate, rename, and delete directories
 * Supports FAT12, FAT16, FAT32, exFAT, and LFN with Unicode

Limitations:
 * Async drivers not supported
 * FAT volumes limited by the size of a Javascript ArrayBuffer, which is much less than exFAT limits.
 * Does not include FatFS's code page conversion capabilities

## Getting Started
fatfs-wasm can be used from Node.js or the browser.

In the browser, include `fatfs.min.js`, which makes `fatfs-wasm` available in the window namespace:
```html
<script src="fatfs.min.js"></script>
<script>
    const { FatFsDisk } = window['fatfs-wasm']
    // ...
</script>
```

Using npm
```
npm install --save fatfs-wasm
```
Then in Javascript
```typescript
const { FatFsDisk, FatFsFormat, FatFsMode } = require('fatfs-wasm')
```

## Using
FatFs can be used with typed arrays to create disk images:
```typescript
const data = new Uint8Array(1 << 23);
const disk = await FatFsDisk.create(data);
disk.mkfs();   // Format filesystem
disk.mount();  // Mount workspace
```

Create partitions on one in-memory physical disk:
```typescript
const data = new Uint8Array(24 * 1024 * 1024);
const disk = await FatFsDisk.create(data);
disk.fdisk([50, 50]);
disk.mkfs({ path: '0:' });
disk.mkfs({ path: '1:' });
```

Use the exFAT/GPT-capable WASM build when needed:
```typescript
const { FatFsDisk, FatFsFormat } = require('fatfs-wasm');

const disk = await FatFsDisk.create(data, { exfat: true });
disk.mkfs({ fmt: FatFsFormat.EXFAT });
```

Or open existing ones:
```typescript
const response = await fetch('disk.img');
const data = new Uint8Array(await response.arrayBuffer());
const disk = await FatFsDisk.create(data);
disk.mount();  // Mount workspace
```

Once a workspace is mounted, the library provides APIs for manipulating files:
```typescript
const file = disk.open('file.txt', FatFsMode.READ);
const buffer = new Uint8Array(1024);
file.read(buffer);
file.close();

// Or, for convenience:
const contents = disk.readFile('file.txt');
```

As well as iterating directories 
```typescript
const dir = disk.openDir('folder');
for (const file of dir) {
    // ...
}
dir.close();
```

See the API documentation for details

## API Documentation

[API Documentation](./docs/modules.md)

## Modifying FatFs C Code
FatFS has many feature gates defined using the preprocessor. See `native/ff16/source/ffconf.h` to make adjustments. Please note that any changes to the C code must be reflected in the `src/fatfs.ts` wrapper, which is not automatically generated. Make changes at your own risk.

To build, open a terminal in MacOS, Linux, or WSL with clang installed and run the build script:
```
cd native
./build.sh
```
This will build `ff.wasm` and `ff_exfat.wasm` and copy them to the `src` directory.


## Running Tests
```
npx vitest
```

---
_Source: https://npm.io/package/fatfs-wasm · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
