feat: more compression ig

This commit is contained in:
TrèsAbhi committed 2024-02-04 21:40:40 -06:00
1 parent 6753cedd33
commit 3b1066fade
3 files changed
+24 -15

No files matched your search

+7
View File
@@ -2,6 +2,13 @@
A compact binary representation similar to JSON objects. This documentation uses some funky (yet concise) syntax I developed (don't worry, my C++ isn't that bad!).
1. JSON compressed as BKON, written directly to disk (a direct 50% reduction).
2. BKON further compressed with LZ4 (a clean 90% reduction).
3. The raw JSON file as fetched from a random data source.
4. BKON decompressed once again to JSON. Note that this file is a little larger than the original JSON file as it contains a lot more decimal places due to float conversion precision.
![an image of file sizes](https://i.imgur.com/9rBnOuS.png)
## Primitives
```cpp
+7 -15
View File
@@ -190,9 +190,13 @@ export class BkonWriteStream extends WriteStream {
}
}
} else {
// floats... ignore for now
this.uint8(ValueType.Uint32);
this.uint32(0);
if (object < -0x80000000 || object > 0x7fffffff) {
this.uint8(ValueType.Float64);
this.float64(object);
} else {
this.uint8(ValueType.Float32);
this.float32(object);
}
}
} else if (typeof object === 'bigint') {
if (object < 0) {
@@ -275,15 +279,3 @@ export class BkonWriteStream extends WriteStream {
this.ascii('BKON');
}
}
// const write = new BkonWriteStream();
// const data = (await fetch(
// 'https://raw.githubusercontent.com/tresabhi/blitzkrieg-assets/dev/definitions/tanks.json',
// ).then((response) => response.json())) as Value;
// write.bkon(data);
// const buffer = write.buffer;
// const read = new BkonReadStream(buffer);
// read.bkon();
// writeFile('test.bkon', buffer);
// writeFile('test.json', JSON.stringify(data));
+10
View File
@@ -143,4 +143,14 @@ export class WriteStream {
}
return this;
}
float32(value: number) {
const array = new Float32Array([value]);
this.array.push(...new Uint8Array(array.buffer));
return this;
}
float64(value: number) {
const array = new Float64Array([value]);
this.array.push(...new Uint8Array(array.buffer));
return this;
}
}