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

gpusher

v2.2.0

Published

Git over HTTP with Push and Fetch Events

Downloads

27

Readme

Fork of substack/pushover and strongloop-forks/strong-fork-pushover

gpusher allows one to have control as a middleware between git and the http transport. It does so by providing *.git/* routes over (req,res), executing rpc calls to git and then streaming back the response of such calls.

Quickstart

Fetch the package:

npm i gpusher

set up the handler:

const express = require('express');
const gpusher = require('gpusher');

const port = 8000;
const app = express();
const repos = gpusher('/tmp/gpusher');

repos.on('push', p => {
  console.log(
    'branch=%s\nrepo=%s\ncommit=%s',
    p.branch, p.commit, p.repo,
  );
  p.accept();
});

app.all('/*', repos.handle.bind(repos)); 

app.listen(port, () => {
  console.log('listening on %d', port);
});

Clone a repository:

git clone http://localhost:8000/myrepo

Push something to there:

cd myrepo
echo "hue" > file.txt
git add --all .
git commit -m 'something'
git push origin master

See the output in the server stdout:

listening on 8000
branch=master
repo=8788e1576ba150daeff969e74107a9ffbfa20b1c
commit=myrepo

Use cases

Rate-limiting big pushes

The handle function takes three arguments, being the last one an optional opts mapping:

function handle (req, res, opts);

where opts can take the following values:

// a function that takes a repository (string) and returns
// a `through` function that takes a chunk and then decides what 
// to do with it. In order to forward the chunk into the next pipe
// just `this.queue(chunk)`;
opts.transform = function (repo) { 
  // return a `through` function
  return function (chunk) { 
    this.queue(chunk);
  }
}

This transform method creator allows one to inject code into the pipe stream from request to git rpc sitting right after the decoding phase (when gzip decoder is sending bytes ahead).

This way one can create a rate-limiter:

  let server = http.createServer((req, res) => {
    function rateLimitter(repo) {
      let limit = 1024;
      return function bytesCounter(chunk) {
        limit -= chunk.length;
        if (limit > 0) {
          return this.queue(chunk);
        }

        this.emit('error', new Error('quota limit reached'));
      };
    }

    repos.handle(req, res, {
      transform: rateLimitter,
    });
  });

Performing a request and streaming the response to the client

const fs = require('fs');
const http = require('http');

const request = require('request');
const gpusher = require('gpusher');
const through2 = require('through2');
const sideband = require('git-side-band-message');

const repos = gpusher('/tmp/repositories');

repos.on('push', push => {
  console.log('push');

  push.on('response', (res, done) => {
    // this is a 3MB+ stream from 1 to 575286
    request('https://dl.filla.be/aiTJodJ_k')
      .pipe(
        through2((chunk, enc, cb) => {
          console.log('writing chunk');
          res.write(sideband(chunk));
          cb();
        })
      )
      .on('finish', () => {
        console.log('finish');
        done();
      });
  });

  console.log('push accepted');
  push.accept();
});

http
  .createServer((req, res) => {
    repos.handle(req, res);
  })
  .listen(8000);

Build Status