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 🙏

© 2025 – Pkg Stats / Ryan Hefner

hubfs.js

v1.0.0

Published

Github API wrapper to writeFile and readFile

Readme

hubfs.js

build status

Github API wrapper to writeFile and readFile

Hubfs(options)

A mixin for Octokat.js that provides a simple wrapper for writing to and reading from a repo. It replicates node.js fs.readFile and fs.writeFile. It has a few special features:

  1. Minimize requests

    By default it tries to use the Github contents API to read, write with a single request and update a file with 3 requests: (a) tries to write; (b) gets sha for existing file; (c) writes update

  2. Read and update large files

    The contents API cannot read or update files larger than 1Mb. Hubfs switches to the git API to read and update files up to 100Mb

  3. Simultaneous writes

    Repeatedly writing to the contents API will result in an error because of delays updating the HEAD, and making multiple simultaneous writes will result in the same problem of Fast Forward commits. Hubfs will automatically queue up requests and switch to using the git API for multiple parallel writes. It will batch together multiple writes to the same repo in commits of up to 10 files, but will make commits as quickly as it can.

Limitations

  • Repeat writes do not currently respect options.flags='wx' (they will overwrite existing files)

  • Maximum batch size for commits cannot be changed, awaiting upstream async issue

Breaking change in v1.0.0

No longer operates as a Octokat mixin, instead new instances are created with an options object with the owner, repo and auth, which is passed to Octokat.

Parameters

| parameter | type | description | | --------- | ------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | options | Object | options.owner Github repo owner, options.repo repo name, options.auth (optional) passed through to a new Octokat instance |

Example

var Hubfs = require('Hubfs')

var options = {
  owner: 'github_username',
  repo: 'github_repo_name'
  auth: {
    username: "USER_NAME",
    password: "PASSWORD"
  }
}

var gh = Hubfs(options)

Returns Object, returns and instance of Hubfs with two methods readFile and writeFile.

writeFile(filename, data, [options], callback)

Asynchronously writes data to a file on Github, replacing the file if it already exists. data can be a string or a buffer.

The encoding option is ignored if data is a buffer. It defaults to 'utf8'.

The file path is always interpreted from the root of the repo, whether or not it is preceded by a slash.

Parameters

| parameter | type | description | | ----------- | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | filename | String | | | data | String,Buffer | | | [options] | Object | optional: options.encoding='utf8' options.flag='w' default will overwrite, 'wx' will fail if path exists. options.message Commit message. options.branch='master' branch to write to. | | callback | Function | |

Example

gh.writeFile('message.txt', 'Hello Github', function (err) {
  if (err) throw err
  console.log('It\'s saved!')
})

readFile(filename, [options], callback)

Asynchronously read a file on Github.

The file path is always interpreted from the root of the repo, whether or not it is preceded by a slash.

The callback is passed two arguments (err, data), where data is the contents of the file.

If no encoding is specified, then the raw buffer is returned.

Parameters

| parameter | type | description | | ----------- | -------- | --------------------------------------------------------------------------------------------------------- | | filename | String | | | [options] | Object | optional: options.encoding=null (returns Buffer) options.ref='master' name of the commit/branch/tag | | callback | Function | |

Example

gh.readFile('/my_folder/my_file.txt', function (err, data) {
  if (err) throw err
  console.log(data)
})

Installation

Requires nodejs.

$ npm install hubfs.js

Tests

$ npm test