Git Product home page Git Product logo

node-ext2fs's Introduction

node-ext2fs

WASM bindings to the linux ext{2,3,4} filesystem library

node-ext2fs uses the e2fsprogs project to provide access to ext filesystem from javascript.

The node- in node-ext2fs is here because it was a native node module until v3.0.0 (excluded). Since v3.0.0, it is a WebAssembly module built with emscripten.

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:

$ npm install node-ext2fs

Building

To build node-ext2fs you need to have make and emcc from emscripten >= 2.0.7 available on your environment.

Build node-ext2fs using npm:

$ npm run build

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

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

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 (fs) => {
                                const readdir = promisify(fs.readdir);
				// List files
                                console.log('readdir', await 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);
        }
}

Support

If you're having any problems, please raise an issue on GitHub.

License

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

node-ext2fs's People

Contributors

zvin avatar balena-ci avatar petrosagg avatar pimterry avatar jhermsmeier avatar jviotti avatar xginn8 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.