mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-24 03:59:50 +02:00
asdads
This commit is contained in:
1 parent
34c742555d
commit
2960f85671
2 files changed
+23
-1
No files matched your search
+1
-1
@@ -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).
|
1. JSON compressed as BKON, written directly to disk (a direct 50% reduction).
|
||||||
2. BKON further compressed with LZ4 (a clean 90% reduction).
|
2. BKON further compressed with LZ4 (a clean 90% reduction).
|
||||||
3. The raw JSON file as fetched from a random data source.
|
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.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
|
import { writeFile } from 'fs/promises';
|
||||||
import { times } from 'lodash';
|
import { times } from 'lodash';
|
||||||
|
import { decode, encode } from 'lz4';
|
||||||
import { ReadStream, WriteStream } from './buffer';
|
import { ReadStream, WriteStream } from './buffer';
|
||||||
|
|
||||||
enum ValueType {
|
enum ValueType {
|
||||||
@@ -279,3 +281,23 @@ export class BkonWriteStream extends WriteStream {
|
|||||||
this.ascii('BKON');
|
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()),
|
||||||
|
);
|
||||||
Reference in new issue
Block a user