A TCP server that listens for own filepaths and streams out its indicated file or directory. Got a method to consume from such peers. And a simple access control mechanism.
npm install --save fs-plug
var plug =// alice and bob on two different computers in the same local networkvar a =var b =// alice allows file to be consumed by peers requesting ita// listen for connectionsa
var plug = fsPlug([opts][, onconsumer(err, mypath)])
Create a new plug. Options default to:
dereference: false // follow symlinks when looking up requested files?enforceWhitelist: true // only serve files if they have been whitelisted before?timeout: 500 // max number of ms to wait for initial bytes when consumingpassphrase: undefined // if buffer or string require this passphrase for every requestwhitelist: undefined // string seed the plug's whitelist with these file pathsinterval: 250 // emit interval for the bytes-supplied and bytes-consumed events
onconsumer will be called every time a file or directory has been supplied to a consumer or in case of an error during that process.
plug.consume(conf, callback(err, localPath))
Consume from another plug.
conf must be an object with the following properties:
port: numberhost: stringtype: string // either 'file' or 'directory'remotePath: string // absolute filepath on serving machinelocalPath: string // local filepath for consumed filepassphrase: string // sesameopen
Whitelist a file or directory on your machine to be shared with requesting consumers. Whitelisting is not required if a plug has been instantiated with
Disallow sharing a resource if the plug has been instantiated with
Toggle requiring a whitelist check by passing a boolean.
Clear the plug's whitelist.
Set or reset the passphrase for authorizing inbound requests.
passphrase msut be a
Read-only property indicating the number of files and directories supplied.
Read-only property indicating the number of files and directories consumed.
plug.on('bytes-supplied', callback(socketid, num))
Emitted while writing to a socket.
num is the number of bytes supplied through the socket indicated by
plug.on('bytes-consumed', callback(socketid, num))
Emitted while consuming from a socket.
num is the number of bytes consumed so far through the socket indicated by