UNPKG

@hamstudy/flamp

Version:

JavaScript Amateur Multicast Protocol AMP-2 Version 3 Implemented from specification document http://www.w1hkj.com/files/flamp/Amp-2.V3.0.Protocol.pdf • Version 1.0.0 - W5ALT, Walt Fair, Jr. (Derived From) • Version 2.0.0 - W1HKJ, Dave Freese, w

38 lines (37 loc) 1.13 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const lzma_1 = require("./lzma"); class CompressorHolder { constructor() { this.cMap = {}; const prefix = "\u0002LZMA"; this.addCompressor({ prefix, compress: str => prefix + lzma_1.encodeSync(str, 1), decompress: str => { if (str.startsWith(prefix)) { return lzma_1.decodeSync(str.substring(prefix.length)); } else { throw new Error("Invalid compressed string"); } }, }); } addCompressor(compressor) { this.default = compressor.prefix; this.cMap[compressor.prefix] = compressor; } getCompressor(prefix = this.default) { return this.cMap[prefix]; } getDecompressor(buffer) { for (let c of Object.values(this.cMap)) { if (buffer.substring(0, c.prefix.length) == c.prefix) { return c; } } return null; } } exports.Compressor = new CompressorHolder();