Skip to content

Use Node's native zlib #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 0 additions & 15 deletions Makefile

This file was deleted.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Library that provides simple object-oriented api for working with git data at a
lower level, see [git internals](http://git-scm.com/book/en/Git-Internals) for more info:

#### Installation

```sh
npm install git-core
```
Expand Down
33 changes: 0 additions & 33 deletions binding.gyp

This file was deleted.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "git-core",
"version": "0.0.4",
"version": "0.0.5",
"description": "Simple library for working git core structures(blobs, trees, commits, tags and packs) without a repository",
"main": "./src/js/index.js",
"main": "./src/index.js",
"scripts": {
"test": "make test"
"test": "mocha --ui tdd test/all.js"
},
"repository": {
"type": "git",
Expand All @@ -15,7 +15,6 @@
"git-objects"
],
"devDependencies": {
"node-gyp": "*",
"wrench": "*",
"less": "*",
"mocha": "*",
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
127 changes: 0 additions & 127 deletions src/cpp/zlib.cpp

This file was deleted.

File renamed without changes.
File renamed without changes.
52 changes: 0 additions & 52 deletions src/js/zlib.js

This file was deleted.

2 changes: 1 addition & 1 deletion src/js/pack.js → src/pack.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ Pack.prototype.serialize = function() {
return Buffer.concat(contentArray);
}

Pack.deserialize = function(buffer, resolveBase) {
Pack.deserialize = function(buffer, resolveBase, callback) {
var i, count, objPos, pos, type, entryHeader, inflatedEntry, inflatedData
, ofsDeltaHeader, base, baseOffset, baseId, patchedData, pendingDelta
, deserialized, k, size, keys, serialized
Expand Down
File renamed without changes.
File renamed without changes.
47 changes: 47 additions & 0 deletions src/zlib.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var _zlib = require('zlib');
var returnCodes = {
Z_OK: _zlib.Z_OK,
Z_STREAM_END: _zlib.Z_STREAM_END,
Z_NEED_DICT: _zlib.Z_NEED_DICT,
Z_ERRNO: _zlib.Z_ERRNO,
Z_STREAM_ERROR: _zlib.Z_STREAM_ERROR,
Z_DATA_ERROR: _zlib.Z_DATA_ERROR,
Z_MEM_ERROR: _zlib.Z_MEM_ERROR,
Z_BUF_ERROR: _zlib.Z_BUF_ERROR,
Z_VERSION_ERROR: _zlib.Z_VERSION_ERROR
};

// idea stolen from node.js zlib bindings
Object.keys(returnCodes).forEach(function(k) {
returnCodes[returnCodes[k]] = k;
});


function checkBuffer(data) {
if (!(data instanceof Buffer))
throw new Error('expecting buffer');
}

function checkError(returnValue) {
if (typeof returnValue === 'number')
throw new Error(returnCodes[returnValue]);
}

function deflate(data) {
checkBuffer(data);

var info = _zlib.deflateSync(data, {info: true});

return info.buffer;
}

function inflate(data, inflatedsize) {
checkBuffer(data);

var info = _zlib.inflateSync(data, {info: true});

return [ info.buffer, info.engine.bytesRead ];
}

exports.deflate = deflate;
exports.inflate = inflate;
Loading