• Stars
    star
    312
  • Rank 134,133 (Top 3 %)
  • Language
    C++
  • License
    MIT License
  • Created over 9 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Notice: We published the successor module to this here https://github.com/fuse-friends/fuse-native

fuse-bindings

NOTICE

We published the successor module to this at https://github.com/fuse-friends/fuse-native

Fully maintained fuse bindings for Node that aims to cover the entire FUSE api

npm install fuse-bindings

Compared to fuse4js these bindings cover almost the entire FUSE api (except for locking) and doesn't do any buffer copys in read/write. It also supports unmount and mouting of multiple fuse drives.

Requirements

You need to have FUSE installed (or Dokany on Windows)

  • On Linux/Ubuntu sudo apt-get install libfuse-dev
  • On OSX
    • if you use Brew, install OSXFuse and brew install pkg-config
    • if you use MacPorts, sudo port install osxfuse +devel
  • On Windows install Dokany

Windows

WARNING: Dokany is still not quite stable. It can cause BSODs. Be careful.

Using this on Windows is slightly more complicated. You need to install Dokany (for dokanfuse.lib, dokanctl.exe, driver and service) and clone its repo (for the headers).

Once the Dokany repo is cloned, you also need to set environment variable DOKAN_INSTALL_DIR to the path to DokenLibrary of your Dokany installaton, and DOKAN_FUSE_INCLUDE to the path to *dokany repo*\dokan_fuse\include.

EDIT: Dokany now includes needed headers and sets proper environment variables when installing! Just install Dokany and this module should install and work just fine! (Drop an issue otherwise)

Usage

Try creating an empty folder called mnt and run the below example

var fuse = require('fuse-bindings')

var mountPath = process.platform !== 'win32' ? './mnt' : 'M:\\'

fuse.mount(mountPath, {
  readdir: function (path, cb) {
    console.log('readdir(%s)', path)
    if (path === '/') return cb(0, ['test'])
    cb(0)
  },
  getattr: function (path, cb) {
    console.log('getattr(%s)', path)
    if (path === '/') {
      cb(0, {
        mtime: new Date(),
        atime: new Date(),
        ctime: new Date(),
        nlink: 1,
        size: 100,
        mode: 16877,
        uid: process.getuid ? process.getuid() : 0,
        gid: process.getgid ? process.getgid() : 0
      })
      return
    }

    if (path === '/test') {
      cb(0, {
        mtime: new Date(),
        atime: new Date(),
        ctime: new Date(),
        nlink: 1,
        size: 12,
        mode: 33188,
        uid: process.getuid ? process.getuid() : 0,
        gid: process.getgid ? process.getgid() : 0
      })
      return
    }

    cb(fuse.ENOENT)
  },
  open: function (path, flags, cb) {
    console.log('open(%s, %d)', path, flags)
    cb(0, 42) // 42 is an fd
  },
  read: function (path, fd, buf, len, pos, cb) {
    console.log('read(%s, %d, %d, %d)', path, fd, len, pos)
    var str = 'hello world\n'.slice(pos, pos + len)
    if (!str) return cb(0)
    buf.write(str)
    return cb(str.length)
  }
}, function (err) {
  if (err) throw err
  console.log('filesystem mounted on ' + mountPath)
})

process.on('SIGINT', function () {
  fuse.unmount(mountPath, function (err) {
    if (err) {
      console.log('filesystem at ' + mountPath + ' not unmounted', err)
    } else {
      console.log('filesystem at ' + mountPath + ' unmounted')
    }
  })
})

See also

fs-fuse is a wrapper module build on top of fuse-bindings that allow you to export and mount any fs-like object as a FUSE filesystem.

API

fuse.mount(mnt, ops, [cb])

Mount a new filesystem on mnt. Pass the FUSE operations you want to support as the ops argument.

fuse.unmount(mnt, [cb])

Unmount a filesystem

fuse.context()

Returns the current fuse context (pid, uid, gid). Must be called inside a fuse callback.

Mount options

ops.options

Set mount options

ops.options = ['direct_io'] // set the direct_io option

ops.displayFolder

Set to true to make OSX display a folder icon and the folder name as the mount point in finder

ops.force

Set to true to force mount the filesystem (will do an unmount first)

FUSE operations

Most of the FUSE api is supported. In general the callback for each op should be called with cb(returnCode, [value]) where the return code is a number (0 for OK and < 0 for errors). See below for a list of POSIX error codes.

ops.init(cb)

Called on filesystem init.

ops.access(path, mode, cb)

Called before the filesystem accessed a file

ops.statfs(path, cb)

Called when the filesystem is being stat'ed. Accepts a fs stat object after the return code in the callback.

ops.statfs = function (path, cb) {
  cb(0, {
    bsize: 1000000,
    frsize: 1000000,
    blocks: 1000000,
    bfree: 1000000,
    bavail: 1000000,
    files: 1000000,
    ffree: 1000000,
    favail: 1000000,
    fsid: 1000000,
    flag: 1000000,
    namemax: 1000000
  })
}

ops.getattr(path, cb)

Called when a path is being stat'ed. Accepts a stat object (similar to the one returned in fs.stat(path, cb)) after the return code in the callback.

ops.getattr = function (path, cb) {
  cb(0, {
    mtime: new Date(),
    atime: new Date(),
    ctime: new Date(),
    size: 100,
    mode: 16877,
    uid: process.getuid(),
    gid: process.getgid()
  })
}

ops.fgetattr(path, fd, cb)

Same as above but is called when someone stats a file descriptor

ops.flush(path, fd, cb)

Called when a file descriptor is being flushed

ops.fsync(path, fd, datasync, cb)

Called when a file descriptor is being fsync'ed.

ops.fsyncdir(path, fd, datasync, cb)

Same as above but on a directory

ops.readdir(path, cb)

Called when a directory is being listed. Accepts an array of file/directory names after the return code in the callback

ops.readdir = function (path, cb) {
  cb(0, ['file-1.txt', 'dir'])
}

ops.truncate(path, size, cb)

Called when a path is being truncated to a specific size

ops.ftruncate(path, fd, size, cb)

Same as above but on a file descriptor

ops.readlink(path, cb)

Called when a symlink is being resolved. Accepts a pathname (that the link should resolve to) after the return code in the callback

ops.readlink = function (path, cb) {
  cb(null, 'file.txt') // make link point to file.txt
}

ops.chown(path, uid, gid, cb)

Called when ownership of a path is being changed

ops.chmod(path, mode, cb)

Called when the mode of a path is being changed

ops.mknod(path, mode, dev, cb)

Called when the a new device file is being made.

ops.setxattr(path, name, buffer, length, offset, flags, cb)

Called when extended attributes is being set (see the extended docs for your platform). Currently you can read the attribute value being set in buffer at offset.

ops.getxattr(path, name, buffer, length, offset, cb)

Called when extended attributes is being read. Currently you have to write the result to the provided buffer at offset.

ops.listxattr(path, buffer, length, cb)

Called when extended attributes of a path are being listed. buffer should be filled with the extended attribute names as null-terminated strings, one after the other, up to a total of length in length. (ERANGE should be passed to the callback if length is insufficient.) The size of buffer required to hold all the names should be passed to the callback either on success, or if the supplied length was zero.

ops.removexattr(path, name, cb)

Called when an extended attribute is being removed.

ops.open(path, flags, cb)

Called when a path is being opened. flags in a number containing the permissions being requested. Accepts a file descriptor after the return code in the callback.

var toFlag = function(flags) {
  flags = flags & 3
  if (flags === 0) return 'r'
  if (flags === 1) return 'w'
  return 'r+'
}

ops.open = function (path, flags, cb) {
  var flag = toFlag(flags) // convert flags to a node style string
  ...
  cb(0, 42) // 42 is a file descriptor
}

ops.opendir(path, flags, cb)

Same as above but for directories

ops.read(path, fd, buffer, length, position, cb)

Called when contents of a file is being read. You should write the result of the read to the buffer and return the number of bytes written as the first argument in the callback. If no bytes were written (read is complete) return 0 in the callback.

var data = new Buffer('hello world')

ops.read = function (path, fd, buffer, length, position, cb) {
  if (position >= data.length) return cb(0) // done
  var part = data.slice(position, position + length)
  part.copy(buffer) // write the result of the read to the result buffer
  cb(part.length) // return the number of bytes read
}

ops.write(path, fd, buffer, length, position, cb)

Called when a file is being written to. You can get the data being written in buffer and you should return the number of bytes written in the callback as the first argument.

ops.write = function (path, fd, buffer, length, position, cb) {
  console.log('writing', buffer.slice(0, length))
  cb(length) // we handled all the data
}

ops.release(path, fd, cb)

Called when a file descriptor is being released. Happens when a read/write is done etc.

ops.releasedir(path, fd, cb)

Same as above but for directories

ops.create(path, mode, cb)

Called when a new file is being opened.

ops.utimens(path, atime, mtime, cb)

Called when the atime/mtime of a file is being changed.

ops.unlink(path, cb)

Called when a file is being unlinked.

ops.rename(src, dest, cb)

Called when a file is being renamed.

ops.link(src, dest, cb)

Called when a new link is created.

ops.symlink(src, dest, cb)

Called when a new symlink is created

ops.mkdir(path, mode, cb)

Called when a new directory is being created

ops.rmdir(path, cb)

Called when a directory is being removed

ops.destroy(cb)

Both read and write passes the underlying fuse buffer without copying them to be as fast as possible.

Error codes

The available error codes are exposes as well as properties. These include

  • fuse.EPERM === -1
  • fuse.ENOENT === -2
  • fuse.ESRCH === -3
  • fuse.EINTR === -4
  • fuse.EIO === -5
  • fuse.ENXIO === -6
  • fuse.E2BIG === -7
  • fuse.ENOEXEC === -8
  • fuse.EBADF === -9
  • fuse.ECHILD === -10
  • fuse.EAGAIN === -11
  • fuse.ENOMEM === -12
  • fuse.EACCES === -13
  • fuse.EFAULT === -14
  • fuse.ENOTBLK === -15
  • fuse.EBUSY === -16
  • fuse.EEXIST === -17
  • fuse.EXDEV === -18
  • fuse.ENODEV === -19
  • fuse.ENOTDIR === -20
  • fuse.EISDIR === -21
  • fuse.EINVAL === -22
  • fuse.ENFILE === -23
  • fuse.EMFILE === -24
  • fuse.ENOTTY === -25
  • fuse.ETXTBSY === -26
  • fuse.EFBIG === -27
  • fuse.ENOSPC === -28
  • fuse.ESPIPE === -29
  • fuse.EROFS === -30
  • fuse.EMLINK === -31
  • fuse.EPIPE === -32
  • fuse.EDOM === -33
  • fuse.ERANGE === -34
  • fuse.EDEADLK === -35
  • fuse.ENAMETOOLONG === -36
  • fuse.ENOLCK === -37
  • fuse.ENOSYS === -38
  • fuse.ENOTEMPTY === -39
  • fuse.ELOOP === -40
  • fuse.EWOULDBLOCK === -11
  • fuse.ENOMSG === -42
  • fuse.EIDRM === -43
  • fuse.ECHRNG === -44
  • fuse.EL2NSYNC === -45
  • fuse.EL3HLT === -46
  • fuse.EL3RST === -47
  • fuse.ELNRNG === -48
  • fuse.EUNATCH === -49
  • fuse.ENOCSI === -50
  • fuse.EL2HLT === -51
  • fuse.EBADE === -52
  • fuse.EBADR === -53
  • fuse.EXFULL === -54
  • fuse.ENOANO === -55
  • fuse.EBADRQC === -56
  • fuse.EBADSLT === -57
  • fuse.EDEADLOCK === -35
  • fuse.EBFONT === -59
  • fuse.ENOSTR === -60
  • fuse.ENODATA === -61
  • fuse.ETIME === -62
  • fuse.ENOSR === -63
  • fuse.ENONET === -64
  • fuse.ENOPKG === -65
  • fuse.EREMOTE === -66
  • fuse.ENOLINK === -67
  • fuse.EADV === -68
  • fuse.ESRMNT === -69
  • fuse.ECOMM === -70
  • fuse.EPROTO === -71
  • fuse.EMULTIHOP === -72
  • fuse.EDOTDOT === -73
  • fuse.EBADMSG === -74
  • fuse.EOVERFLOW === -75
  • fuse.ENOTUNIQ === -76
  • fuse.EBADFD === -77
  • fuse.EREMCHG === -78
  • fuse.ELIBACC === -79
  • fuse.ELIBBAD === -80
  • fuse.ELIBSCN === -81
  • fuse.ELIBMAX === -82
  • fuse.ELIBEXEC === -83
  • fuse.EILSEQ === -84
  • fuse.ERESTART === -85
  • fuse.ESTRPIPE === -86
  • fuse.EUSERS === -87
  • fuse.ENOTSOCK === -88
  • fuse.EDESTADDRREQ === -89
  • fuse.EMSGSIZE === -90
  • fuse.EPROTOTYPE === -91
  • fuse.ENOPROTOOPT === -92
  • fuse.EPROTONOSUPPORT === -93
  • fuse.ESOCKTNOSUPPORT === -94
  • fuse.EOPNOTSUPP === -95
  • fuse.EPFNOSUPPORT === -96
  • fuse.EAFNOSUPPORT === -97
  • fuse.EADDRINUSE === -98
  • fuse.EADDRNOTAVAIL === -99
  • fuse.ENETDOWN === -100
  • fuse.ENETUNREACH === -101
  • fuse.ENETRESET === -102
  • fuse.ECONNABORTED === -103
  • fuse.ECONNRESET === -104
  • fuse.ENOBUFS === -105
  • fuse.EISCONN === -106
  • fuse.ENOTCONN === -107
  • fuse.ESHUTDOWN === -108
  • fuse.ETOOMANYREFS === -109
  • fuse.ETIMEDOUT === -110
  • fuse.ECONNREFUSED === -111
  • fuse.EHOSTDOWN === -112
  • fuse.EHOSTUNREACH === -113
  • fuse.EALREADY === -114
  • fuse.EINPROGRESS === -115
  • fuse.ESTALE === -116
  • fuse.EUCLEAN === -117
  • fuse.ENOTNAM === -118
  • fuse.ENAVAIL === -119
  • fuse.EISNAM === -120
  • fuse.EREMOTEIO === -121
  • fuse.EDQUOT === -122
  • fuse.ENOMEDIUM === -123
  • fuse.EMEDIUMTYPE === -124

License

MIT

More Repositories

1

peerflix

Streaming torrent client for node.js
JavaScript
6,094
star
2

playback

Video player built using electron and node.js
JavaScript
2,009
star
3

torrent-stream

The low level streaming torrent engine that peerflix uses
JavaScript
1,941
star
4

why-is-node-running

Node is running but you don't know why? why-is-node-running is here to help you.
JavaScript
1,781
star
5

chromecasts

Query your local network for Chromecasts and have them play media
JavaScript
1,447
star
6

csv-parser

Streaming csv parser inspired by binary-csv that aims to be faster than everyone else
JavaScript
1,413
star
7

torrent-mount

Mount a torrent (or magnet link) as a filesystem in real time using torrent-stream and fuse. AKA MAD SCIENCE!
JavaScript
1,333
star
8

turbo-http

Blazing fast low level http server
JavaScript
996
star
9

is-my-json-valid

A JSONSchema validator that uses code generation to be extremely fast
JavaScript
961
star
10

pump

pipe streams together and close all of them if one of them closes
JavaScript
895
star
11

airpaste

A 1-1 network pipe that auto discovers other peers using mdns
JavaScript
819
star
12

hyperdb

Distributed scalable database
JavaScript
752
star
13

protocol-buffers

Protocol Buffers for Node.js
JavaScript
751
star
14

signalhub

Simple signalling server that can be used to coordinate handshaking with webrtc or other fun stuff.
JavaScript
667
star
15

turbo-json-parse

Turbocharged JSON.parse for type stable JSON data
JavaScript
613
star
16

turbo-net

Low level TCP library for Node.js
JavaScript
598
star
17

peercast

torrent-stream + chromecast
JavaScript
509
star
18

hyperbeam

A 1-1 end-to-end encrypted internet pipe powered by Hyperswarm
JavaScript
482
star
19

multicast-dns

Low level multicast-dns implementation in pure javascript
JavaScript
470
star
20

hyperlog

Merkle DAG that replicates based on scuttlebutt logs and causal linking
JavaScript
466
star
21

hypervision

P2P Television
JavaScript
445
star
22

webcat

Mad science p2p pipe across the web using webrtc that uses your Github private/public key for authentication and a signalhub for discovery
JavaScript
437
star
23

tar-stream

tar-stream is a streaming tar parser and generator.
JavaScript
381
star
24

webrtc-swarm

Create a swarm of p2p connections using webrtc and a signalhub
JavaScript
375
star
25

discovery-swarm

A network swarm that uses discovery-channel to find peers
JavaScript
375
star
26

tar-fs

fs bindings for tar-stream
JavaScript
339
star
27

torrent-docker

MAD SCIENCE realtime boot of remote docker images using bittorrent
JavaScript
314
star
28

peerwiki

all of wikipedia on bittorrent
JavaScript
308
star
29

awesome-p2p

List of great p2p resources
301
star
30

hyperfs

A content-addressable union file system build on top of fuse, hyperlog, leveldb and node
JavaScript
270
star
31

respawn

Spawn a process and restart it if it crashes
JavaScript
254
star
32

pumpify

Combine an array of streams into a single duplex stream using pump and duplexify
JavaScript
252
star
33

polo

Polo is a zero configuration service discovery module written completely in Javascript.
JavaScript
246
star
34

benny-hill

Play the Benny Hill theme while running another command
JavaScript
242
star
35

streamx

An iteration of the Node.js core streams with a series of improvements.
JavaScript
224
star
36

mp4-stream

Streaming mp4 encoder and decoder
JavaScript
219
star
37

hyperphone

A telephone over Hyperbeam
JavaScript
198
star
38

flat-file-db

Fast in-process flat file database that caches all data in memory
JavaScript
196
star
39

diffy

A tiny framework for building diff based interactive command line tools.
JavaScript
191
star
40

dns-discovery

Discovery peers in a distributed system using regular dns and multicast dns.
JavaScript
190
star
41

duplexify

Turn a writable and readable stream into a streams2 duplex stream with support for async initialization and streams1/streams2 input
JavaScript
185
star
42

browser-server

A HTTP "server" in the browser that uses a service worker to allow you to easily send back your own stream of data.
JavaScript
185
star
43

browserify-fs

fs for the browser using level-filesystem and browserify
JavaScript
184
star
44

ims

Install My Stuff - an opinionated npm module installer
JavaScript
184
star
45

dns-packet

An abstract-encoding compliant module for encoding / decoding DNS packets
JavaScript
181
star
46

jitson

Just-In-Time JSON.parse compiler
JavaScript
178
star
47

dnsjack

A simple DNS proxy that lets you intercept domains and route them to whatever IP you decide.
JavaScript
172
star
48

nanobench

Simple benchmarking tool with TAP-like output that is easy to parse
JavaScript
169
star
49

localcast

A shared event emitter that works across multiple processes on the same machine, including the browser!
JavaScript
165
star
50

level-filesystem

Full implementation of the fs module on top of leveldb
JavaScript
164
star
51

dht-rpc

Make RPC calls over a Kademlia based DHT.
JavaScript
160
star
52

tetris

Play tetris in your terminal - in color
JavaScript
157
star
53

hyperssh

Run SSH over hyperswarm!
JavaScript
146
star
54

end-of-stream

Call a callback when a readable/writable/duplex stream has completed or failed.
JavaScript
145
star
55

flat-tree

A series of functions to map a binary tree to a list
JavaScript
141
star
56

lil-pids

Dead simple process manager with few features
JavaScript
140
star
57

airswarm

Network swarm that automagically discovers other peers on the network using multicast dns
JavaScript
127
star
58

wat2js

Compile WebAssembly .wat files to a common js module
JavaScript
127
star
59

node-modules

Search for node modules
JavaScript
127
star
60

ssh-exec

Execute a script over ssh using Node.JS
JavaScript
126
star
61

add-to-systemd

Small command line tool to simply add a service to systemd
JavaScript
125
star
62

deejay

Music player that broadcasts to everyone on the same network
JavaScript
124
star
63

protocol-buffers-schema

No nonsense protocol buffers schema parser written in Javascript
JavaScript
120
star
64

tree-to-string

Convert a tree structure into a human friendly string
JavaScript
120
star
65

unordered-array-remove

Efficiently remove an element from an unordered array without doing a splice
JavaScript
117
star
66

hyperpipe

Distributed input/output pipe.
JavaScript
116
star
67

abstract-chunk-store

A test suite and interface you can use to implement a chunk based storage backend
JavaScript
113
star
68

shared-structs

Share a struct backed by the same underlying buffer between C and JavaScript
JavaScript
113
star
69

mininet

Spin up and interact with virtual networks using Mininet and Node.js
JavaScript
113
star
70

p2p-workshop

a workshop to learn about p2p
HTML
111
star
71

jsonkv

Single file write-once database that is valid JSON with efficient random access on bigger datasets
JavaScript
109
star
72

ansi-diff-stream

A transform stream that diffs input buffers and outputs the diff as ANSI. If you pipe this to a terminal it will update the output with minimal changes
JavaScript
109
star
73

browser-sync-stream

Rsync between a server and the browser.
JavaScript
108
star
74

docker-registry-server

docker registry server in node.js
JavaScript
108
star
75

dns-socket

Make custom low-level DNS requests from node with retry support.
JavaScript
102
star
76

utp-native

Native bindings for libutp
JavaScript
100
star
77

taco-nginx

Bash script that runs a service and forwards a subdomain to it using nginx when it listens to $PORT
Shell
100
star
78

gunzip-maybe

Transform stream that gunzips its input if it is gzipped and just echoes it if not
JavaScript
98
star
79

merkle-tree-stream

A stream that generates a merkle tree based on the incoming data.
JavaScript
98
star
80

media-recorder-stream

The Media Recorder API in the browser as a readable stream
JavaScript
97
star
81

thunky

Delay the evaluation of a paramless async function and cache the result
JavaScript
97
star
82

peervision

a live p2p streaming protocol
JavaScript
97
star
83

noise-network

Authenticated P2P network backed by Hyperswarm and Noise
JavaScript
96
star
84

soundcloud-to-dat

Download all music from a Soundcloud url and put it into a Dat
JavaScript
96
star
85

blecat

1-1 pipe over bluetooth low energy
JavaScript
95
star
86

debugment

A debug comment -> debugment
JavaScript
93
star
87

hyperdht

A DHT that supports peer discovery and distributed hole punching
JavaScript
93
star
88

docker-browser-console

Forward input/output from docker containers to your browser
JavaScript
90
star
89

srt-to-vtt

Transform stream that converts srt files to vtt files (html5 video subtitles)
JavaScript
89
star
90

speedometer

speed measurement in javascript
JavaScript
88
star
91

mutexify

Bike shed mutex lock implementation
JavaScript
88
star
92

p2p-file-sharing-workshop

A workshop where you learn about distributed file sharing
HTML
88
star
93

mirror-folder

Small module to mirror a folder to another folder. Supports live mode as well.
JavaScript
87
star
94

utp

utp (micro transport protocol) implementation in node
JavaScript
86
star
95

echo-servers.c

A collection of various echo servers in c
C
83
star
96

recursive-watch

Minimal recursive file watcher
JavaScript
82
star
97

docker-browser-server

Spawn and expose docker containers over http and websockets
JavaScript
80
star
98

are-feross-and-mafintosh-stuck-in-an-elevator

Are @feross and @mafintosh stuck in an elevator?
JavaScript
79
star
99

parallel-transform

Transform stream for Node.js that allows you to run your transforms in parallel without changing the order
JavaScript
79
star
100

peer-wire-swarm

swarm implementation for bittorrent
JavaScript
79
star