deflate stub

This commit is contained in:
BuckarooBanzay 2020-07-02 11:22:01 +02:00
parent 5c588656ee
commit 0769fe217e
20 changed files with 1021 additions and 5 deletions

21
.github/workflows/test.yml vendored Normal file
View File

@ -0,0 +1,21 @@
name: test
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: actions/checkout@v1
- name: apt
run: sudo apt-get install -y nodejs npm
- name: npm install
run: npm i
- name: npm test
run: npm test

919
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -4,8 +4,8 @@
"description": "mapcleaner", "description": "mapcleaner",
"main": "index.js", "main": "index.js",
"scripts": { "scripts": {
"jshint_backend": "cd src && jshint .", "jshint_backend": "cd src && jshint . && cd ../test/ && jshint .",
"test": "echo \"Error: no test specified\" && exit 1" "test": "mocha"
}, },
"repository": { "repository": {
"type": "git", "type": "git",
@ -22,6 +22,7 @@
"pq": "0.0.3" "pq": "0.0.3"
}, },
"devDependencies": { "devDependencies": {
"jshint": "^2.11.1" "jshint": "^2.11.1",
"mocha": "^8.0.1"
} }
} }

View File

@ -4,7 +4,5 @@
"esversion": 6, "esversion": 6,
"node": true, "node": true,
"globals": { "globals": {
"describe": true,
"it": true
} }
} }

55
src/mapblockparser.js Normal file
View File

@ -0,0 +1,55 @@
const zlib = require("zlib");
module.exports.parse = function(data){
const buffer = Buffer.from(data);
let offset = 0;
// version stuff
const version = buffer.readUInt8(offset);
if (version < 25 || version > 28) {
throw new Error("mapblock version not supported: " + version);
}
if (version >= 27) {
offset = 4;
} else {
//u16 lighting_complete not present
offset = 2;
}
// content
const content_width = buffer.readUInt8(offset);
const params_width = buffer.readUInt8(offset+1);
if (content_width != 2 || params_width != 2){
throw new Error("content/param width mismatch!")
}
//mapdata (blocks)
if (version >= 27) {
offset = 6;
} else {
offset = 4;
}
const metadata_buffer = buffer.subarray(offset);
const inflate = zlib.createInflate();
inflate.on("data", function(e){
console.log("event", e);
console.log(inflate.bytesWritten);
});
inflate.write(metadata_buffer);
console.log(inflate);
const metadata = zlib.inflateSync(metadata_buffer);
return {
version: version
};
};

10
test/.jshintrc Normal file
View File

@ -0,0 +1,10 @@
{
"undef": true,
"unused": true,
"esversion": 6,
"node": true,
"globals": {
"describe": true,
"it": true
}
}

12
test/mapblockparser.js Normal file
View File

@ -0,0 +1,12 @@
const assert = require('assert');
const mapblockparser = require("../src/mapblockparser");
const fs = require("fs");
describe('mapblockparser', function() {
it('deserializes node names', function() {
const data = fs.readFileSync("./test/testdata/0.0.0");
const mapblock = mapblockparser.parse(data);
assert.equal(mapblock.version, 28);
});
});

BIN
test/testdata/0.-1.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.0.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.1.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.10.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.2.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.3.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.4.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.5.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.6.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.7.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.8.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/0.9.0 vendored Normal file

Binary file not shown.

BIN
test/testdata/11.0.2 vendored Normal file

Binary file not shown.