@runejs/core
Version:
Core logging, networking, and buffer functionality for RuneJS applications.
26 lines • 1.13 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.Bzip2 = void 0;
const tslib_1 = require("tslib");
const buffer_1 = require("../buffer");
const compressjs = tslib_1.__importStar(require("compressjs"));
const bzip = compressjs.Bzip2;
const charCode = (letter) => letter.charCodeAt(0);
class Bzip2 {
static compress(rawFileData) {
const compressedFile = new buffer_1.ByteBuffer(bzip.compressFile(rawFileData, undefined, 1));
// Do not include the BZip compression level header because the client expects a headerless BZip format
return new buffer_1.ByteBuffer(compressedFile.slice(4, compressedFile.length));
}
static decompress(compressedFileData) {
const buffer = Buffer.alloc(compressedFileData.length + 4);
compressedFileData.copy(buffer, 4);
buffer[0] = charCode('B');
buffer[1] = charCode('Z');
buffer[2] = charCode('h');
buffer[3] = charCode('1');
return new buffer_1.ByteBuffer(bzip.decompressFile(buffer));
}
}
exports.Bzip2 = Bzip2;
//# sourceMappingURL=bzip2.js.map