This commit is contained in:
TrèsAbhi committed 2024-02-04 21:45:57 -06:00
1 parent 34c742555d
commit 2960f85671
2 files changed
+23 -1

No files matched your search

+1 -1
View File
@@ -5,7 +5,7 @@ A compact binary representation similar to JSON objects. This documentation uses
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.
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 precision.
![an image of file sizes](https://i.imgur.com/9rBnOuS.png)
+22
View File
@@ -1,4 +1,6 @@
import { writeFile } from 'fs/promises';
import { times } from 'lodash';
import { decode, encode } from 'lz4';
import { ReadStream, WriteStream } from './buffer';
enum ValueType {
@@ -279,3 +281,23 @@ 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();
const lz4 = encode(buffer);
writeFile('test.bkon', buffer);
writeFile('test.json', JSON.stringify(data));
writeFile('test.bkon.lz4', lz4);
// now we attempt to read it
writeFile(
'test.read.json',
JSON.stringify(new BkonReadStream(decode(lz4)).bkon()),
);