Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
add readme & npm codes
  • Loading branch information
sisong committed Apr 6, 2021
commit 8552fdde7891f70783a4b31e96fb58711931f12b
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ bower_components

# Compiled binary addons (https://nodejs.org/api/addons.html)
build/Release
build/Debug

# Dependency directories
node_modules/
Expand Down Expand Up @@ -102,3 +103,4 @@ dist

# TernJS port file
.tern-port
.idea
2 changes: 2 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
build
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
# node-hdiffpatch
# node-hdiffpatch

Create patch buffer with origin buffer with [HDiffPatch](https://github.com/sisong/HDiffPatch)

Patch compatible with HDiffPatch -SD

## Installation

```bash
npm install --save node-hdiffpatch
```

## Usage

### diff(originBuf, newBuf)

Compare two buffers and return a new hdiffpatch patch as return value.
35 changes: 35 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"targets": [
{
"target_name": "hdiffpatch",
"sources": [
"src/main.cc",
"src/hdiff.cpp",
"HDiffPatch/libHDiffPatch/HPatch/patch.c",
"HDiffPatch/file_for_patch.c",
"HDiffPatch/libHDiffPatch/HDiff/diff.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/bytes_rle.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/suffix_string.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/compress_detect.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/digest_matcher.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/stream_serialize.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort64.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/libdivsufsort/divsufsort.cpp",
"HDiffPatch/libHDiffPatch/HDiff/private_diff/limit_mem_diff/adler_roll.cpp",
"lzma/C/LzFind.c",
"lzma/C/LzmaDec.c",
"lzma/C/LzmaEnc.c",
"lzma/C/Lzma2Dec.c",
"lzma/C/Lzma2Enc.c"
],
"defines": [
"_IS_NEED_DIR_DIFF_PATCH=0",
"_7ZIP_ST",
"_IS_USED_MULTITHREAD=0"
],
"include_dirs" : [
"<!(node -e \"require('nan')\")"
]
}
]
}
21 changes: 21 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by housisong on 2021.04.06.
*/

var native;
try {
native = require('./build/Release/hdiffpatch');
} catch(e) {
console.error(e);
native = require('./build/Debug/hdiffpatch');
}
exports.native = native;

exports.diff = function(oldBuf, newBuf) {
var buffers = [];
native.diff(oldBuf, newBuf, function(output){
buffers.push(output);
});

return Buffer.concat(buffers);
}
21 changes: 21 additions & 0 deletions index_test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Created by housisong on 2021.04.06.
*/

var native;
try {
native = require('./build/Release/hdiffpatch');
} catch(e) {
console.error(e);
native = require('./build/Debug/hdiffpatch');
}
exports.native = native;

exports.diff = function(oldBuf, newBuf) {
var buffers = [];
native.diff(oldBuf, newBuf, function(output){
buffers.push(output);
});

return Buffer.concat(buffers);
}
29 changes: 29 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"name": "node-hdiffpatch",
"version": "0.1.5",
"description": "hdiffpatch port to node.js",
"main": "index.js",
"scripts": {
"test": "node test/test.js"
},
"gypfile": true,
"author": "housisong",
"license": "MIT",
"dependencies": {
"nan": "^2.14.0"
},
"devDependencies": {
"md5": "^2.2.1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/reactnativecn/node-hdiffpatch"
},
"keywords": [
"hdiffpatch"
],
"bugs": {
"url": "https://github.com/reactnativecn/node-hdiffpatch/issues"
},
"homepage": "https://github.com/reactnativecn/node-hdiffpatch#readme"
}
21 changes: 21 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var hdiffpatch = require("../index");
var test_hdiffpatch = require("../index_test");
var crypto = require("crypto");
var md5 = require("md5");
var assert = require("assert").strict;

var cur = crypto.randomBytes(40960);

var ref = Buffer.concat([
Buffer.from("fdsa"),
cur.slice(0, 4096),
Buffer.from("asdf"),
cur.slice(4096),
Buffer.from("asdf")
]);

assert.deepStrictEqual(
md5(hdiffpatch.diff(cur, ref)),
md5(test_hdiffpatch.diff(cur, ref))
);
console.log("pass");
49 changes: 49 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
# yarn lockfile v1


amdefine@~1.0.0:
version "1.0.1"
resolved "https://registry.yarnpkg.com/amdefine/-/amdefine-1.0.1.tgz#4a5282ac164729e93619bcfd3ad151f817ce91f5"
integrity sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=

charenc@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/charenc/-/charenc-0.0.2.tgz#c0a1d2f3a7092e03774bfa83f14c0fc5790a8667"
integrity sha1-wKHS86cJLgN3S/qD8UwPxXkKhmc=

commander@~2.8.1:
version "2.8.1"
resolved "https://registry.yarnpkg.com/commander/-/commander-2.8.1.tgz#06be367febfda0c330aa1e2a072d3dc9762425d4"
integrity sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=
dependencies:
graceful-readlink ">= 1.0.0"

crypt@~0.0.1:
version "0.0.2"
resolved "https://registry.yarnpkg.com/crypt/-/crypt-0.0.2.tgz#88d7ff7ec0dfb86f713dc87bbb42d044d3e6c41b"
integrity sha1-iNf/fsDfuG9xPch7u0LQRNPmxBs=

"graceful-readlink@>= 1.0.0":
version "1.0.1"
resolved "https://registry.yarnpkg.com/graceful-readlink/-/graceful-readlink-1.0.1.tgz#4cafad76bc62f02fa039b2f94e9a3dd3a391a725"
integrity sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=

is-buffer@~1.1.1:
version "1.1.6"
resolved "https://registry.yarnpkg.com/is-buffer/-/is-buffer-1.1.6.tgz#efaa2ea9daa0d7ab2ea13a97b2b8ad51fefbe8be"
integrity sha512-NcdALwpXkTm5Zvvbk7owOUSvVvBKDgKP5/ewfXEznmQFfs4ZRmanOeKBTjRVjka3QFoN6XJ+9F3USqfHqTaU5w==

md5@^2.2.1:
version "2.2.1"
resolved "https://registry.yarnpkg.com/md5/-/md5-2.2.1.tgz#53ab38d5fe3c8891ba465329ea23fac0540126f9"
integrity sha1-U6s41f48iJG6RlMp6iP6wFQBJvk=
dependencies:
charenc "~0.0.1"
crypt "~0.0.1"
is-buffer "~1.1.1"

nan@^2.14.0:
version "2.14.0"
resolved "https://registry.yarnpkg.com/nan/-/nan-2.14.0.tgz#7818f722027b2459a86f0295d434d1fc2336c52c"
integrity sha512-INOFj37C7k3AfaNTtX8RhsTw7qRy7eLET14cROi9+5HAVbbHuIWUHEauBv5qT4Av2tWasiTY1Jw6puUNqRJXQg==