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

git-core

v0.0.4

Published

Simple library for working git core structures(blobs, trees, commits, tags and packs) without a repository

Downloads

20

Readme

node-git-core

Library that provides simple object-oriented api for working with git data at a lower level, see git internals for more info:

Installation

npm install git-core

Usage

git = require('git-core');
Blob = git.Blob;
Tree = git.Tree;
Commit = git.Commit;
Tag = git.Tag;
Pack = git.Pack;

b1 = new Blob('Some file');

b2 = new Blob(new Buffer([1,2,3,4,5])); // blob with binary data

b3 = new Blob('Another file\n');

// (For now file modes are not supported on trees, all blobs have mode 100644 and
// subtrees have mode 040000)

t1 = new Tree({
  'file-under-tree': b3
});

t2 = new Tree({
  'some-file.txt': b2,
  'some-file2.txt': b1,
  'sub-directory.d': t1
});

t3 = new Tree({
  'another-file.txt': b1
});

// Lets create some commmits

c1 = new Commit({
  tree: t1,
  author: {
    name: 'Git Author',
    email: '[email protected]',
    date: d1
  },
  message: 'Artificial commit 1'
});

c2 = new Commit({
  tree: t2,
  author: {
    name: 'Git Author',
    email: '[email protected]',
    date: d2
  },
  message: 'Artificial commit 2',
  parents: [c1]
});

c3 = new Commit({
  tree: t3,
  author: {
    name: 'Git User',
    email: '[email protected]',
    date: d3
  },
  committer: {
    name: 'Git Commiter',
    email: '[email protected]',
    date: d4
  },
  message: 'Artificial commit 3',
  parents: [c2]
});

tag = new Tag({
  object: c2,
  name: 'v0.0.1',
  tagger: {
    name: 'Git Tagger',
    email: '[email protected]'
  },
  date: d2,
  message: 'Tag second commit'
});

// Lets pack everything toguether

pack = new Pack([c3, tag]);
serializedPack = pack.serialize(); // this is a git packfile

// We only need to add a head to the pack, all other will be added
// automatically when serializing

This library is all about working with git data in-memory, no repositories are needed. Above is an example on how git objects can be created, connected and serialized, the inverse is also supported:

// Lets say 'buffer' contains a packfile data that you read from disk or
// received from 'git-fetch-pack'

pack = Pack.deserialize(buffer);

// pack now contains a ready-to-use git object graph

// print all blobs in the pack
for (var i = 0;i < pack.objects.length;i++) {
  var obj = pack.objects[i];
  if (obj instanceof Blob) {
    console.log(obj.serialize().getHash(), ':', obj.contents.toString()));
  }
}

// deserialization of 'thin packs' is also supported, you just have to pass a
// callback as a second argument to 'deserialize', which will be called with
// the sha1 id whenever a base object is required

pack = Pack.deserialize(buffer, function(baseSha1) {
  // fetch the object with 'baseSha1' id from somewhere and return
});

Delta compression is only fully supported on 'deserialization. If you need to encode objects using delta compression then add the deltas manually:

str = '';
for (i = _i = 0; _i < 1000; i = ++_i) {
  str += 'test content/test content2/test content3\n';
}

b1 = new Blob(str);
b2 = new Blob(str + 'append\n');
b3 = new Blob(str + 'append\nappend2\n');
b4 = new Blob(str + 'append\nappend2\nappend3\n');

pack = new Pack([
  b1,
  b2.diff(b1),
  b3.diff(b2),
  b4.diff(b3)
]);
pack.serialize();