npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

fs-plug

v0.3.0

Published

tcp server for simple file sharing

Downloads

13

Readme

fs-plug

build status AppVeyor Build Status


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.


Get it!

npm install --save fs-plug

Usage

var plug = require('fs-plug')

// alice and bob on two different computers in the same local network
var a = plug()
var b = plug()

// alice allows file to be consumed by peers requesting it
a.whitelist(__filename)

// listen for connections
a.listen(10000, function() {
  // bobs consume config
  var conf = {
    port: 10000,
    host: "localhost",
    type: "file",
    remotePath: __filename,
    localPath: "example"
  }
  // bob consuming from alice
  b.consume(conf, function(err, localPath) {
    if (err) return console.error(err)
    console.log("file saved as:", localPath)
    a.close()
    b.close()
  })
})

API

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 consuming
  passphrase: undefined // if buffer or string require this passphrase for every request
  whitelist: undefined // string[] seed the plug's whitelist with these file paths
  interval: 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: number,
  host: string,
  type: string, // either 'file' or 'directory'
  remotePath: string, // absolute filepath on serving machine
  localPath: string // local filepath for consumed file
  passphrase: string // sesameopen
}

plug.whitelist(filepath)

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 !opts.enforceWhitelist.

plug.blacklist(filepath)

Disallow sharing a resource if the plug has been instantiated with opts.enforceWhitelist.

plug.enforceWhitelist(bool)

Toggle requiring a whitelist check by passing a boolean.

plug.clearWhitelist()

Clear the plug's whitelist.

plug.setPassphrase(passphrase)

Set or reset the passphrase for authorizing inbound requests. passphrase msut be a Buffer or string.

plug.supplied

Read-only property indicating the number of files and directories supplied.

plug.consumed

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 socketid.

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 socketid.


License

MIT