From f6dcf4b6806dda23140e76832264c4624f00acf7 Mon Sep 17 00:00:00 2001 From: Andrew Osheroff Date: Tue, 17 Dec 2019 11:08:02 +0100 Subject: [PATCH] Update README.md --- README.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/README.md b/README.md index a1c46d5..ea89318 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,66 @@ Multithreaded FUSE bindings for Node JS. * Embedded shared library support means users do not have to install FUSE from a 3rd party. * API support for initial FUSE kernel extension configuration so you can control the user experience. +## Installation +``` +npm i fuse-native --save +``` + +## Example +```js +const ops = { + readdir: function (path, cb) { + if (path === '/') return cb(null, ['test']) + return cb(Fuse.ENOENT) + }, + getattr: function (path, cb) { + if (path === '/') return cb(null, stat({ mode: 'dir', size: 4096 })) + if (path === '/test') return cb(null, stat({ mode: 'file', size: 11 })) + return cb(Fuse.ENOENT) + }, + open: function (path, flags, cb) { + return cb(0, 42) + }, + release: function (path, fd, cb) { + return cb(0) + }, + read: function (path, fd, buf, len, pos, cb) { + var str = 'hello world'.slice(pos, pos + len) + if (!str) return cb(0) + buf.write(str) + return cb(str.length) + } +} + +const fuse = new Fuse(mnt, ops, { debug: true }) +fuse.mount(function (err) { + fs.readFile(path.join(mnt, 'test'), function (err, buf) { + // buf should be 'hello world' + }) +}) +``` + ## API +In order to create a FUSE mountpoint, you first need to create a `Fuse` object that wraps a set of implemented FUSE syscall handlers: + +#### `const fuse = new Fuse(mnt, handlers, opts = {})` +Create a new `Fuse` object. + +`mnt` is the string path of your desired mountpoint. +`handlers` is an object mapping syscall names to implementations. The complete list of available syscalls is described below. As an example, if you wanted to implement a filesystem that only supports `getattr`, your handle object would look like: +```js +{ + getattr: function (path, cb) { + if (path === '/') return process.nextTick(cb, null, stat({ mode: 'dir', size: 4096 })) + if (path === '/test') return process.nextTick(cb, null, stat({ mode: 'file', size: 11 })) + return process.nextTick(cb, Fuse.ENOENT) + } +} +``` + +The following FUSE API methods are supported: + +### FUSE API TODO