# git-packfile

> git packfile library for looking up and decoding git objects

Latest version **1.0.0** (published 2016-06-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install git-packfile
pnpm add git-packfile
yarn add git-packfile
bun add git-packfile
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2016-06-18 |
| First published | 2013-03-17 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 5 |
| Author | Chris Dickinson |
| Maintainers | chrisdickinson |
| Keywords | git, packfile |

## Links

- npm: https://www.npmjs.com/package/git-packfile
- Repository: https://github.com/chrisdickinson/git-packfile
- Homepage: https://github.com/chrisdickinson/git-packfile#readme
- Issues: https://github.com/chrisdickinson/git-packfile/issues
- npm.io page: https://npm.io/package/git-packfile

## Dependencies (2)

- [through](https://npm.io/package/through.md) ~2.2.7
- [git-apply-delta](https://npm.io/package/git-apply-delta.md) 0.0.7

## Recent versions

- 1.0.0 (latest) — 2016-06-18
- 0.0.4 — 2013-05-27
- 0.0.3 — 2013-03-23
- 0.0.2 — 2013-03-19
- 0.0.1 — 2013-03-17

## README

# git-packfile

read object data out of git packfiles, applying
ofs/ref deltas and zlib decompression.

[![Build Status](https://travis-ci.org/chrisdickinson/git-packfile.png)](https://travis-ci.org/chrisdickinson/git-packfile)
[![browser support](http://ci.testling.com/chrisdickinson/git-packfile.png)](http://ci.testling.com/chrisdickinson/git-packfile)

```javascript
var packfile = require('git-packfile')
  , idxparse = require('git-packidx-parser')

fs.createReadStream('path/to/idx')
  .pipe(idxparse())
  .on('data', next)

function next(packIndex) {
  var pack = packfile(
        fs.statSync('path/to/packfile')
      , lookup
      , readStream
  )

  lookup(<some git hash as a buffer>, function(err, object) {
    // obj === {type: git type number, data: buffer}
  })

  function readStream(start, end) {
    return fs.createReadStream('path/to/packfile', {
      start: start
    , end: end
    })
  }

  function lookup(oid, ready) {
    var location = packIndex.find(oid)
    pack.read(location.offset, location.next, ready)
  }
} 

```

## API

#### packfile(size, lookupRef, createReadStream) -> Packfile instance

create a packfile instance. all arguments are required.

`lookupRef` should be a function that takes a buffer instance and a callback,
and calls that callback with the results of searching for that hash against all
available object databases. 

`createReadStream` is a function that takes a byte start and end, and should
return a readable stream object.

#### Packfile#read(offset, nextOffset, ready)

Read from offset until nextOffset (given by [the pack index](http://npm.im/git-packidx-parser)), and calls `ready` with the result.

Returned objects look like so:

```javascript
{ type: <integer git object type>
, data: <Buffer> }
```

The data is decompressed and has all deltas already applied to it.

## License

MIT

---
_Source: https://npm.io/package/git-packfile · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
