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-blob-stream

v0.0.14

Published

Node.js Transform streams to convert data to or from git blobs

Downloads

579

Readme

git-blob-stream

Build Status

WARNING This package is still under active development, I reserve the right to change anything until 0.1.0 is released. At that point I'll go all SemVer and everything.

This npm package makes it easy and efficient to read and write Git blob files using node.js Stream2 streams. It has no dependencies on command line git or native code git libraries; instead using crypto and compression libraries already built into node.js.

Installation

npm install git-blob-stream

# To run tests from within the package directory
npm install && npm test

Usage

To read a blob file:
var fs = require('fs');
var gbs = require('git-blob-stream');

var input = fs.createReadStream("filename.blob");
var output = fs.createWriteStream("filename");

var headerFunc = function (err, ret) {
  // ret is an object:
  // { size: <blobDataLength>, type: <blobType> }
};

var xformStream = gbs.blobReader({
    noOutput: false    // Default, if true, no data will be readable
  },
  headerFunc);      // callback is optional

// Decode the file...
input.pipe(xformStream).pipe(output);

output.on('close', function () {
  // All done
});
To write a blob file:
var fs = require('fs');
var gbs = require('git-blob-stream');

var input = fs.createReadStream("filename");
var output = fs.createWriteStream("filename.blob");

var hashFunc = function (err, ret) {
  // ret is an object:
  // { size: <blobDataLength>, hash: <hashValue> }
  // hashValue is a hex string of the 20 byte SHA1 sum
}

// All options are manditory!
var xformStream = gbs.blobWriter({
  size: fs.statSync("filename").size,  // Optional, but more efficient if provided!
  type: "blob",                        // Default, or "tree", "tag" or "commit"
  noOutput: false                      // Default, if true, no data will be written
  },
  hashFunc); // callback is optional

// Write the file. hashCallback will be called when finished
input.pipe(xformStream).pipe(output);

output.on('close', function () {
  // All done
});

Higher level git objects

In addition to blobs, this package can also stream to/from js-git style tree, commit and tag objects.

To read a tree blob file:
var fs = require('fs');
var gbs = require('git-blob-stream');
var input = fs.createReadStream("tree.blob");

var callback = function (err, ret) {
  // ret is a tree object
}

var xformStream = gbs.treeReader(callback); // callback is optional

// Decode the file...
output = input.pipe(xformStream);

// If a callback is not provided to treeReader, then it writes its output
// as an object to the stream output
// output.on('data', function (data) {
//   // data is a tree object
//   // This will only be called once
// });
//
// output.on('end', function () {
//   // All done
// });
To write a tree blob file:
var fs = require('fs');
var gbs = require('git-blob-stream');

var output = fs.createWriteStream("tree.blob");

var hashFunc = function (ret) {
  // ret is an object:
  // { size: <blobDataLength>, hash: <hashValue>, tree: <normalizedTreeObj>}
  // hashValue is a hex string of the 20 byte SHA1 sum
  // normalizedTreeObj is the actual tree object that would be read back, as
  // normalized to git standard form (canonical sorting, missing fields added)
}

// All options are manditory!
var xformStream = gbs.treeWriter(
  {
    'greetings.txt' : { mode: gbs.gitModes.file, hash: fileHash }
  },
  hashFunc); // callback is optional

// Write the file. hashCallback will be called when finished
xformStream.pipe(output);

output.on('close', function () {
  // All done
});

Analogous calls for reading/writing commits and (annotated) tags also exist: commitReader, commitWriter, tagReader, tagWriter. All assume js-git style objects.

Enjoy!