# ext2fs

> WASM bindings to libext2fs for cross-platform ext filesystem handling

Latest version **4.2.5** (published 2025-03-25) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install ext2fs
pnpm add ext2fs
yarn add ext2fs
bun add ext2fs
```

## Health

**Score 40/100 (D)** — status: stable.

Positive: no vulnerabilities; high maintenance score.

Warnings: low downloads; no types; no esm support.

Negative: stale.

## Facts

| | |
|---|---|
| Version | 4.2.5 |
| Published | 2025-03-25 |
| First published | 2017-06-13 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=16 |
| Dependencies | 0 |
| Unpacked size | 415.8 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 31 |
| Author | Balena Ltd. |
| Maintainers | balena.io |
| Keywords | extfs, ext, ext2, ext3, ext4, filesystem, fs |

## Links

- npm: https://www.npmjs.com/package/ext2fs
- Repository: https://github.com/balena-io/node-ext2fs
- Homepage: https://github.com/balena-io/node-ext2fs#readme
- Issues: https://github.com/balena-io/node-ext2fs/issues
- npm.io page: https://npm.io/package/ext2fs

## Alternatives

- [unionfs](https://npm.io/package/unionfs.md) — 2.2M weekly downloads
- [path-starts-with](https://npm.io/package/path-starts-with.md) — 35.9K weekly downloads
- [redzip](https://npm.io/package/redzip.md) — 1.2K weekly downloads
- [vscode-anymatch](https://npm.io/package/vscode-anymatch.md) — 848 weekly downloads
- [@ledgerhq/coin-filecoin](https://npm.io/package/@ledgerhq/coin-filecoin.md) — 793 weekly downloads

## Recent versions

- 4.2.5 (latest) — 2025-03-25
- 4.2.5-build-renovate-major-11-mocha-3318a93c4cbc8411cad60bb2af15ba30c17aa11a-1 (build-renovate-major-11-mocha) — 2025-02-20
- 4.2.4-build-ryan-filesize-34e52e843f4fcc4d3704025103aae87b2951db9d-1 (build-ryan-filesize) — 2025-02-20
- 4.2.3-build-kyle-patch-51e3de3486f529f0de413da56aca83b8db25c032-1 (build-kyle-patch) — 2023-12-19
- 4.2.3-build-kyle-patch-a60ee96e76b6d6b979bec2f74677e0cda13dcc15-1 (build-kyle-patch-a60ee96e76b6d6b979bec2f74677e0cda13dcc15) — 2023-12-19
- 4.2.3-build-kyle-patch-669c7c9069e6d0712fcb484ba86bfbe9fa2b9374-1 (build-kyle-patch-669c7c9069e6d0712fcb484ba86bfbe9fa2b9374) — 2023-12-19
- 4.2.2-build-renovate-prettier-3-x-beed62e3ef5a43d15f98d5468c9aed9256fe3ff5-1 (build-renovate-prettier-3-x-beed62e3ef5a43d15f98d5468c9aed9256fe3ff5) — 2023-07-05
- 4.2.1-build-support-node-18-b3a66b86840dbf0a81a0430b827941cc2cd72639-1 (build-support-node-18-b3a66b86840dbf0a81a0430b827941cc2cd72639) — 2023-01-20
- 4.2.0-build-support-node-18-61d15d710366835e24565ff9957523043db49d7e-1 (build-support-node-18-61d15d710366835e24565ff9957523043db49d7e) — 2023-01-20
- 4.2.0-build-support-node-18-cfa60364dc928842a30048024c682e6fbc57706a-1 (build-support-node-18-cfa60364dc928842a30048024c682e6fbc57706a) — 2023-01-20
- 4.1.7-build-ab77-operational-ebb275b0f548905a5ab9f53b9b5363e060b857f4-2 (build-ab77-operational) — 2023-01-05
- 4.1.6-build-renovate-mocha-10-x-1f29ba37e1aeb9b4ebd918f40dcabc5a1e74ca76-1 (build-renovate-mocha-10-x-1f29ba37e1aeb9b4ebd918f40dcabc5a1e74ca76) — 2022-12-28
- 4.1.5-build-renovate-eslint-8-x-fcb776f2d8119d76cca8ffbbf84ccf113c3074e9-1 (build-renovate-eslint-8-x-fcb776f2d8119d76cca8ffbbf84ccf113c3074e9) — 2022-12-28
- 4.1.4-build-update-flowzone-e6a0e75276f382704da2c3b8a58bd6a4a84571ee-1 (build-update-flowzone-e6a0e75276f382704da2c3b8a58bd6a4a84571ee) — 2022-12-28
- 4.1.3-build-async-fns-098f767f306e544bb2da92880077b539288b7b74-1 (build-async-fns-098f767f306e544bb2da92880077b539288b7b74) — 2022-12-28
- … 133 more at https://npm.io/package/ext2fs/versions

## README

node-ext2fs
=========
### WASM bindings to the linux ext{2,3,4} filesystem library

node-ext2fs uses the [e2fsprogs](https://github.com/tytso/e2fsprogs) project to
provide access to ext filesystem from javascript. It is a WebAssembly module built
with [emscripten](https://emscripten.org/).

Some things you can do with this module:

* Read/write files in a filesystem image directly without mounting
* Use familiar APIs, node-ext2fs has the exact same interface as node's `fs` module
* Combine node-ext2fs filesystem streams with host filesystem streams (e.g copy files)
* Create a tar archive from a filesystem image
* Perform a TRIM operation to obtain discard regions of a filesystem

## Installation

Simply install `node-ext2fs` using `npm`:

``` bash
$ npm install ext2fs
```


## Development

Just run:

```
$ cd ./node-ext2fs
$ npm install
```

If installation fails due to missing executables, see `./install-toolchain.sh`
for help on installing the toolchain.


## Usage

Mount a disk image and use the returned `fs` object.
The fs returned object behaves like node's `fs` except it doesn't provide any
xxxxSync method.
You can also issue `DISCARD` requests using the fs `async trim()` method.

See the example below.

## Example

```javascript
const { withMountedDisk } = require('ext2fs');
const { FileDisk, withOpenFile } = require('file-disk');

async function main() {
  const diskImage = '/some/disk.image';
  const offset = 272629760;  // offset of the ext partition you want to mount in that disk image
  try {
    await withOpenFile(diskImage, 'r', async (handle) => {
      const disk = new FileDisk(handle);
      await withMountedDisk(disk, offset, async ({promises:fs}) => {
        // List files
        console.log('readdir', await fs.readdir('/'));
        await fs.trim();
        // Show discarded regions
        console.log('discarded', disk.getDiscardedChunks());
        // Show ranges of useful data aligned to 1MiB
        console.log('ranges', await disk.getRanges(1024 ** 2));
      });
    });
  } catch (error) {
    console.error(error);
  }
}

```
## Building

- Prerequisites
  * git
  * make
  * NodeJS >=v12


- Install emscripten
```
# Get the emsdk repo
git clone https://github.com/emscripten-core/emsdk.git

# Enter that directory
cd emsdk

# Download and install the latest SDK tools.
./emsdk install latest

# Make the "latest" SDK "active" for the current user. (writes .emscripten file)
./emsdk activate latest

# Activate PATH and other environment variables in the current terminal
source ./emsdk_env.sh
```

- Clone recursively
```
# You must clone recursively in order to get the dependency
git clone --recursive https://github.com/balena-io-modules/node-ext2fs
```

- Build
```
cd node-ext2fs
npm i
npm run build
```

## Support

If you're having any problems, please [raise an issue][github-issue] on GitHub.

## License

node-ext2fs is free software, and may be redistributed under the terms specified
in the [license].

[github-issue]: https://github.com/balena-io/node-ext2fs/issues/new
[license]: https://github.com/balena-io/node-ext2fs/blob/master/LICENSE

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