@malvineous/gamecomp
Advanced tools
Comparing version 1.0.3 to 1.0.4
@@ -106,3 +106,3 @@ /** | ||
let lastDictCode = (1 << lenCodeword) - 1; | ||
let cwPrev = null, chPrev = 0; | ||
let cwPrev = null; | ||
let offCW = 0; | ||
@@ -128,2 +128,5 @@ while (bs.bitsLeft >= lenCodeword) { | ||
} | ||
if (options.resetCodewordLen) { | ||
lenCodeword = options.initialBits; | ||
} | ||
continue; | ||
@@ -138,8 +141,15 @@ } | ||
// codeword again. | ||
dictVal = dictEntry(dict, cwPrev); | ||
// Append the first char onto the end of the dictionary string. This | ||
// is what happens when we add it to the dictionary below, so it's | ||
// like we are writing out the dictionary value for this codeword | ||
// just before it has made it into the dictionary. | ||
dictVal.push(dictVal[0]); | ||
if (dict[cwPrev] !== undefined) { | ||
dictVal = dictEntry(dict, cwPrev); | ||
// Append the first char onto the end of the dictionary string. This | ||
// is what happens when we add it to the dictionary below, so it's | ||
// like we are writing out the dictionary value for this codeword | ||
// just before it has made it into the dictionary. | ||
if (dict.length <= lastDictCode) { // unless the dict is full | ||
dictVal.push(dictVal[0]); | ||
} | ||
} else { | ||
console.error(`Previous codeword ${cwPrev} isn't in the dictionary! Aborting.`); | ||
break; | ||
} | ||
} | ||
@@ -152,7 +162,9 @@ | ||
// character we just wrote. | ||
dict.push({ | ||
ptr: cwPrev, | ||
ch: dictVal[0], | ||
//full: [...(dict[cwPrev] && dict[cwPrev].full || []), dictVal[0]], | ||
}); | ||
if (dict.length <= lastDictCode) { // unless the dict is full | ||
dict.push({ | ||
ptr: cwPrev, | ||
ch: dictVal[0], | ||
//full: [...(dict[cwPrev] && dict[cwPrev].full || []), dictVal[0]], | ||
}); | ||
} | ||
@@ -175,5 +187,17 @@ if (Debug.enabled) { | ||
// Time to extend bitwidth | ||
Debug.log('Codeword reached maximum width at', lenCodeword, 'bits, now at', dictSize, 'of', lastDictCode); | ||
lenCodeword++; | ||
lastDictCode = (1 << lenCodeword) - 1; | ||
Debug.log('Codeword reached maximum width at', lenCodeword, 'bits, now at', dict.length, 'of', lastDictCode); | ||
if (lenCodeword < options.maxBits) { | ||
lenCodeword++; | ||
lastDictCode = (1 << lenCodeword) - 1; | ||
} else { | ||
// Reached maximum codeword length | ||
if (options.resetDictWhenFull) { | ||
Debug.log('Emptying dictionary'); | ||
resetDict(); | ||
if (options.resetCodewordLen) { | ||
lenCodeword = options.initialBits; | ||
} | ||
} | ||
} | ||
Debug.log('Codeword size is now', lenCodeword, 'bits'); | ||
} | ||
@@ -180,0 +204,0 @@ } |
@@ -42,3 +42,3 @@ /** | ||
static reveal(content, options = {}) | ||
static reveal(content) | ||
{ | ||
@@ -76,3 +76,3 @@ try { | ||
static obscure(content, options = {}) { | ||
static obscure(content) { | ||
try { | ||
@@ -79,0 +79,0 @@ const md = this.metadata(); |
@@ -23,4 +23,2 @@ /** | ||
const Debug = require('../util/utl-debug.js'); | ||
const FORMAT_ID = 'enc-xor-blood'; | ||
@@ -27,0 +25,0 @@ |
{ | ||
"name": "@malvineous/gamecomp", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Apply and remove compression and encryption algorithms used by DOS games", | ||
@@ -32,3 +32,5 @@ "main": "index.js", | ||
"devDependencies": { | ||
"mocha": "^5.2.0" | ||
"eslint": "^5.9.0", | ||
"mocha": "^5.2.0", | ||
"mocha-eslint": "^4.1.0" | ||
}, | ||
@@ -35,0 +37,0 @@ "dependencies": { |
@@ -20,4 +20,2 @@ /** | ||
const assert = require('assert'); | ||
const TestUtil = require('./util.js'); | ||
@@ -50,4 +48,4 @@ const standardCleartext = require('./gen-cleartext.js'); | ||
const contentRevealed = handler.reveal(contentInput); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
testutil.buffersEqual(content.default, contentInput, 'Input buffer was changed during reveal'); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(content.default, contentInput, 'Input buffer was changed during reveal'); | ||
}); | ||
@@ -61,4 +59,4 @@ }); | ||
const contentObscured = handler.obscure(contentInput); | ||
testutil.buffersEqual(content.default, contentObscured); | ||
testutil.buffersEqual(standardCleartext, contentInput, 'Input buffer was changed during obscure'); | ||
TestUtil.buffersEqual(content.default, contentObscured); | ||
TestUtil.buffersEqual(standardCleartext, contentInput, 'Input buffer was changed during obscure'); | ||
}); | ||
@@ -72,3 +70,3 @@ }); | ||
const contentRevealed = handler.reveal(contentObscured); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -75,0 +73,0 @@ }); |
@@ -20,3 +20,2 @@ /** | ||
const assert = require('assert'); | ||
const BitStream = require('bit-buffer').BitStream; | ||
@@ -29,3 +28,2 @@ | ||
function makeU8(as) { | ||
if (!as.join) console.log(as); | ||
let s = as.join(''); | ||
@@ -107,3 +105,3 @@ let ab = new ArrayBuffer(s.length); | ||
const contentRevealed = handler.reveal(content[id], p.params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -126,3 +124,3 @@ }); | ||
const contentRevealed = handler.reveal(new Uint8Array(input), presets.mbash.params); | ||
testutil.buffersEqual(makeU8(expected), contentRevealed); | ||
TestUtil.buffersEqual(makeU8(expected), contentRevealed); | ||
}); | ||
@@ -142,3 +140,3 @@ | ||
const contentRevealed = handler.reveal(new Uint8Array(input), presets.mbash.params); | ||
testutil.buffersEqual(makeU8(expected), contentRevealed); | ||
TestUtil.buffersEqual(makeU8(expected), contentRevealed); | ||
}); | ||
@@ -158,3 +156,3 @@ | ||
const contentRevealed = handler.reveal(new Uint8Array(input), presets.mbash.params); | ||
testutil.buffersEqual(makeU8(expected), contentRevealed); | ||
TestUtil.buffersEqual(makeU8(expected), contentRevealed); | ||
}); | ||
@@ -175,3 +173,3 @@ | ||
const contentRevealed = handler.reveal(new Uint8Array(input), presets.mbash.params); | ||
testutil.buffersEqual(makeU8(expected), contentRevealed); | ||
TestUtil.buffersEqual(makeU8(expected), contentRevealed); | ||
}); | ||
@@ -188,3 +186,3 @@ | ||
const contentObscured = handler.obscure(standardCleartext, p.params); | ||
testutil.buffersEqual(content[id], contentObscured); | ||
TestUtil.buffersEqual(content[id], contentObscured); | ||
}); | ||
@@ -207,3 +205,3 @@ }); | ||
const contentObscured = handler.obscure(makeU8(input), presets.mbash.params); | ||
testutil.buffersEqual(expected, contentObscured); | ||
TestUtil.buffersEqual(expected, contentObscured); | ||
}); | ||
@@ -223,3 +221,3 @@ | ||
const contentObscured = handler.obscure(makeU8(input), presets.mbash.params); | ||
testutil.buffersEqual(expected, contentObscured); | ||
TestUtil.buffersEqual(expected, contentObscured); | ||
}); | ||
@@ -239,3 +237,3 @@ | ||
const contentObscured = handler.obscure(makeU8(input), presets.mbash.params); | ||
testutil.buffersEqual(expected, contentObscured); | ||
TestUtil.buffersEqual(expected, contentObscured); | ||
}); | ||
@@ -256,3 +254,3 @@ | ||
const contentObscured = handler.obscure(makeU8(input), presets.mbash.params); | ||
testutil.buffersEqual(expected, contentObscured); | ||
TestUtil.buffersEqual(expected, contentObscured); | ||
}); | ||
@@ -270,3 +268,3 @@ | ||
const contentRevealed = handler.reveal(contentObscured, p.params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -273,0 +271,0 @@ }); |
@@ -20,4 +20,2 @@ /** | ||
const assert = require('assert'); | ||
const TestUtil = require('./util.js'); | ||
@@ -28,3 +26,2 @@ const GameCompression = require('../index.js'); | ||
const md = handler.metadata(); | ||
let testutil = new TestUtil(md.id); | ||
describe(`Extra tests for ${md.title} [${md.id}]`, function() { | ||
@@ -38,3 +35,3 @@ | ||
const contentRevealed = handler.reveal(b_obs); | ||
testutil.buffersEqual(b_rev, contentRevealed); | ||
TestUtil.buffersEqual(b_rev, contentRevealed); | ||
}); | ||
@@ -44,3 +41,3 @@ | ||
const contentObscured = handler.obscure(b_rev); | ||
testutil.buffersEqual(b_obs, contentObscured); | ||
TestUtil.buffersEqual(b_obs, contentObscured); | ||
}); | ||
@@ -47,0 +44,0 @@ } |
@@ -20,4 +20,2 @@ /** | ||
const assert = require('assert'); | ||
const TestUtil = require('./util.js'); | ||
@@ -48,3 +46,3 @@ const standardCleartext = require('./gen-cleartext.js'); | ||
const contentRevealed = handler.reveal(content.seed4f, params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -55,3 +53,3 @@ | ||
const contentRevealed = handler.reveal(content.seed4f, params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -62,3 +60,3 @@ | ||
const contentRevealed = handler.reveal(content.default_v300, params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -69,3 +67,3 @@ | ||
const contentRevealed = handler.reveal(content.seed4f_v300, params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -76,3 +74,3 @@ | ||
const contentRevealed = handler.reveal(content.default_full, params); | ||
testutil.buffersEqual(standardCleartext, contentRevealed); | ||
TestUtil.buffersEqual(standardCleartext, contentRevealed); | ||
}); | ||
@@ -87,3 +85,3 @@ | ||
const contentObscured = handler.obscure(standardCleartext, params); | ||
testutil.buffersEqual(content.seed4f, contentObscured); | ||
TestUtil.buffersEqual(content.seed4f, contentObscured); | ||
}); | ||
@@ -94,3 +92,3 @@ | ||
const contentObscured = handler.obscure(standardCleartext, params); | ||
testutil.buffersEqual(content.seed4f, contentObscured); | ||
TestUtil.buffersEqual(content.seed4f, contentObscured); | ||
}); | ||
@@ -97,0 +95,0 @@ |
@@ -27,3 +27,3 @@ /** | ||
function addRow(i) { | ||
s += (i - 15).toString(16).padStart(6, '0') + ' ' + h + ' ' + t + "\n"; | ||
s += (i - 15).toString(16).padStart(6, '0') + ' ' + h + ' ' + t + '\n'; | ||
h = t = ''; | ||
@@ -65,3 +65,11 @@ } | ||
buffersEqual(expected, actual, msg) { | ||
loadData(filename) { | ||
const buffer = fs.readFileSync(path.resolve(__dirname, this.idHandler, filename)); | ||
let ab = new ArrayBuffer(buffer.length); | ||
let u8 = new Uint8Array(ab); | ||
u8.set(buffer); | ||
return u8; | ||
} | ||
static buffersEqual(expected, actual, msg) { | ||
if (expected instanceof ArrayBuffer) { | ||
@@ -91,9 +99,5 @@ expected = new Uint8Array(expected); | ||
loadData(filename) { | ||
const buffer = fs.readFileSync(path.resolve(__dirname, this.idHandler, filename)); | ||
let ab = new ArrayBuffer(buffer.length); | ||
let u8 = new Uint8Array(ab); | ||
u8.set(buffer); | ||
return u8; | ||
static u8FromString(s) { | ||
return Uint8Array.from(s.split(''), s => s.charCodeAt(0)); | ||
} | ||
}; |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53757
29
1390
3