feat: deploy new compression

This commit is contained in:
TrèsAbhi committed 2024-02-05 17:30:30 -06:00
1 parent 1575b803c0
commit 63084d1855
10 files changed
+10312 -6090

No files matched your search

@@ -1,8 +1,6 @@
import { GithubChangeBlob, createBlob } from './createBlob';
import { octokit } from './octokit';
const TIME_PER_BLOB = 2 ** 4 * 1000;
export interface FileChange {
path: string;
content: string;
+3 -3
View File
@@ -1,8 +1,8 @@
import { encode } from 'lz4';
import { compress } from 'lz4js';
import { BkonWriteStream } from '../streams/bkon';
export function superCompress(object: any) {
const write = new BkonWriteStream().bkon(object);
const compressed = encode(write.buffer);
return compressed.toString('base64');
const compressed = compress(write.buffer);
return Buffer.from(compressed).toString('base64');
}
+2 -2
View File
@@ -1,8 +1,8 @@
import { decode } from 'lz4';
import { decompress } from 'lz4js';
import { BkonReadStream } from '../streams/bkon';
export function superDecompress<Type>(buffer: Buffer) {
const decompressed = decode(buffer);
const decompressed = Buffer.from(decompress(buffer));
const read = new BkonReadStream(decompressed);
return read.bkon() as Type;
}
+27 -8
View File
@@ -40,21 +40,25 @@ export class BkonReadStream extends ReadStream {
this.magic();
const header = this.header();
const body = this.body(header.fastStringFormat, header.stringTable);
return body;
}
magic() {
if (this.ascii(4) !== 'BKON') {
throw new Error('Invalid BKON magic number');
const magic = this.ascii(4);
if (magic !== 'BKON') {
throw new Error(`Invalid Bkon magic number: "${magic}"`);
}
}
header() {
const version = this.uint16();
const fastStringFormat = this.uint8() as FastStringFormat;
return {
version: this.uint16(),
fastStringFormat: this.uint8() as FastStringFormat,
stringTable: this.stringTable(),
version,
fastStringFormat,
stringTable: this.stringTable(fastStringFormat),
};
}
@@ -65,8 +69,23 @@ export class BkonReadStream extends ReadStream {
return this.value(fastStringFormat, stringTable);
}
stringTable() {
const count = this.uint16();
stringTable(fastStringFormat: FastStringFormat) {
let count: number;
switch (fastStringFormat) {
case FastStringFormat.Format8:
count = this.uint8();
break;
case FastStringFormat.Format16:
count = this.uint16();
break;
case FastStringFormat.Format32:
count = this.uint32();
break;
}
const strings: string[] = [];
for (let index = 0; index < count; index++) {