-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathindex_test.js
More file actions
39 lines (33 loc) · 917 Bytes
/
index_test.js
File metadata and controls
39 lines (33 loc) · 917 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/**
* Created by tdzl2003 on 2/28/16.
*/
var native = require('node-gyp-build')(__dirname);
exports.native = native;
function byteLength(value) {
if (Buffer.isBuffer(value)) {
return value.length;
}
if (ArrayBuffer.isView(value)) {
return value.byteLength;
}
if (value instanceof ArrayBuffer) {
return value.byteLength;
}
throw new TypeError('Expected Buffer, TypedArray, or ArrayBuffer.');
}
exports.diff = function(oldBuf, newBuf) {
var buffers = [];
native.diff(oldBuf, newBuf, function(output){
buffers.push(output);
});
var full = Buffer.concat(buffers);
// Generate bzip2 package with header.
var header = Buffer.alloc(32);
Buffer.from('ENDSLEY/BSDIFF43').copy(header, 0);
header.writeUInt32LE(byteLength(newBuf), 16);
var buffers1 = [header];
native.compress(full, function(output){
buffers1.push(output);
});
return Buffer.concat(buffers1);
}