Compare commits

...

3 Commits

Author SHA1 Message Date
2fb345a177 fix: #51 mmkv parsing
All checks were successful
continuous-integration/drone/push Build is passing
2023-10-11 21:35:21 +01:00
d3385c1902 build: fix build issue with terser 2023-10-11 19:54:18 +01:00
cfbd631815 chore: update deps 2023-10-11 19:41:22 +01:00
8 changed files with 927 additions and 819 deletions

View File

@ -22,9 +22,9 @@
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@jixun/libparakeet": "0.2.1",
"@reduxjs/toolkit": "^1.9.5",
"@reduxjs/toolkit": "^1.9.7",
"framer-motion": "^10.16.4",
"immer": "^10.0.2",
"immer": "^10.0.3",
"nanoid": "^5.0.1",
"radash": "^11.0.0",
"react": "^18.2.0",
@ -32,27 +32,27 @@
"react-dropzone": "^14.2.3",
"react-icons": "^4.11.0",
"react-promise-suspense": "^0.3.4",
"react-redux": "^8.1.2",
"react-redux": "^8.1.3",
"react-syntax-highlighter": "^15.5.0",
"sass": "^1.67.0",
"sass": "^1.69.2",
"sql.js": "^1.8.0"
},
"devDependencies": {
"@rollup/plugin-replace": "^5.0.2",
"@rollup/plugin-replace": "^5.0.3",
"@testing-library/jest-dom": "^6.1.3",
"@testing-library/react": "^14.0.0",
"@testing-library/user-event": "^14.5.1",
"@types/node": "^20.6.2",
"@types/react": "^18.2.21",
"@types/react-dom": "^18.2.7",
"@types/react-syntax-highlighter": "^15.5.7",
"@types/sql.js": "^1.4.4",
"@typescript-eslint/eslint-plugin": "^6.7.0",
"@typescript-eslint/parser": "^6.7.0",
"@vitejs/plugin-react": "^4.0.4",
"@vitest/coverage-v8": "^0.34.4",
"@vitest/ui": "^0.34.4",
"eslint": "^8.49.0",
"@types/node": "^20.8.4",
"@types/react": "^18.2.28",
"@types/react-dom": "^18.2.13",
"@types/react-syntax-highlighter": "^15.5.8",
"@types/sql.js": "^1.4.5",
"@typescript-eslint/eslint-plugin": "^6.7.5",
"@typescript-eslint/parser": "^6.7.5",
"@vitejs/plugin-react": "^4.1.0",
"@vitest/coverage-v8": "^0.34.6",
"@vitest/ui": "^0.34.6",
"eslint": "^8.51.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
@ -61,11 +61,11 @@
"lint-staged": "^14.0.1",
"prettier": "^3.0.3",
"typescript": "^5.2.2",
"vite": "^4.4.9",
"vite": "^4.4.11",
"vite-plugin-pwa": "^0.16.5",
"vite-plugin-top-level-await": "^1.3.1",
"vite-plugin-wasm": "^3.2.2",
"vitest": "^0.34.4"
"vitest": "^0.34.6"
},
"lint-staged": {
"*": "prettier --write --ignore-unknown",
@ -78,6 +78,7 @@
},
"pnpm": {
"patchedDependencies": {
"@rollup/plugin-terser@0.4.3": "patches/@rollup__plugin-terser@0.4.3.patch",
"sql.js@1.8.0": "patches/sql.js@1.8.0.patch"
},
"overrides": {

View File

@ -0,0 +1,22 @@
diff --git a/dist/cjs/index.js b/dist/cjs/index.js
index 23639c70ccd5ebbc4a12c1ba277e5ac81cf30513..aba3318977523785d02f3b8aa6e667a1aa46bf5d 100644
--- a/dist/cjs/index.js
+++ b/dist/cjs/index.js
@@ -227,5 +227,5 @@ function terser(input = {}) {
runWorker();
exports.default = terser;
-module.exports = Object.assign(exports.default, exports);
+module.exports = Object.assign(exports.default, exports, { terser });
//# sourceMappingURL=index.js.map
diff --git a/dist/es/index.js b/dist/es/index.js
index 7296e677e6b2b38df9522b196fee24feec996793..4ca9052dd439ed22ff92cc72a79824b85e229678 100644
--- a/dist/es/index.js
+++ b/dist/es/index.js
@@ -222,5 +222,5 @@ function terser(input = {}) {
runWorker();
-export { terser as default };
+export { terser as default, terser };
//# sourceMappingURL=index.js.map

File diff suppressed because it is too large Load Diff

View File

@ -69,18 +69,21 @@ export class MMKVParser {
return bytesToUTF8String(data).normalize();
}
public readVariantString() {
public readOptionalString() {
// Container [
// len: int,
// data: variant
// ]
const containerLen = this.readInt();
if (containerLen === 0) {
return null;
}
const newOffset = this.offset + containerLen;
const result = this.readString();
if (newOffset !== this.offset) {
const expected = formatHex(newOffset);
const actual = formatHex(this.offset);
throw new Error(`readVariantString failed: offset does mismatch (expect: ${expected}, actual: ${actual})`);
throw new Error(`readVariantString failed: offset mismatch (expect: ${expected}, actual: ${actual})`);
}
return result;
}
@ -99,13 +102,15 @@ export class MMKVParser {
const result = new Map<string, string>();
while (!mmkv.eof) {
const key = mmkv.readString();
const value = mmkv.readVariantString();
result.set(key, value);
const value = mmkv.readOptionalString();
if (value) {
result.set(key, value);
}
}
return result;
}
public static parseKuwoEKey(view: DataView) {
public static parseKuwoEKey(view: DataView): Omit<StagingKWMv2Key, 'id'>[] {
const mmkv = new MMKVParser(view);
const result: Omit<StagingKWMv2Key, 'id'>[] = [];
while (!mmkv.eof) {
@ -117,8 +122,10 @@ export class MMKVParser {
}
const [_, rid, quality] = idMatch;
const ekey = mmkv.readVariantString();
result.push({ rid, quality, ekey });
const ekey = mmkv.readOptionalString();
if (ekey) {
result.push({ rid, quality, ekey });
}
}
return result;
}

View File

@ -1,19 +1,46 @@
import { MMKVParser } from '../MMKVParser';
import { readFileSync } from 'node:fs';
test('parse mmkv file as expected', () => {
const buff = readFileSync(__dirname + '/__fixture__/test.mmkv');
const view = new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
expect(MMKVParser.toStringMap(view)).toEqual(
new Map([
['key', 'value'],
[
'Lorem Ipsum',
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. ' +
'Vestibulum congue volutpat metus non molestie. Quisque id est sapien. ' +
'Fusce eget tristique sem. Donec tellus lacus, viverra sed lectus eget, elementum ultrices dolor. ' +
'Integer non urna justo.',
],
])
);
const makeViewFromBuffer = (buff: Buffer) =>
new DataView(buff.buffer.slice(buff.byteOffset, buff.byteOffset + buff.byteLength));
test('parse qm mmkv file', () => {
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/qm.mmkv'));
expect(Object.fromEntries(MMKVParser.toStringMap(view).entries())).toMatchInlineSnapshot(`
{
"Lorem Ipsum": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum congue volutpat metus non molestie. Quisque id est sapien. Fusce eget tristique sem. Donec tellus lacus, viverra sed lectus eget, elementum ultrices dolor. Integer non urna justo.",
"key": "value",
}
`);
});
test('parse qm mmkv file with optional str', () => {
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/qm_optional.mmkv'));
expect(Object.fromEntries(MMKVParser.toStringMap(view).entries())).toMatchInlineSnapshot(`
{
"key": "value",
"key2": "value2",
}
`);
});
test('parse kuwo mmkv file', () => {
const view = makeViewFromBuffer(readFileSync(__dirname + '/__fixture__/kuwo.mmkv'));
expect(MMKVParser.parseKuwoEKey(view)).toMatchInlineSnapshot(`
[
{
"ekey": "xyz123",
"quality": "20201kmflac",
"rid": "1234567",
},
]
`);
});
test('throw error on broken file', () => {
const view = makeViewFromBuffer(
Buffer.from([0x27, 0x00, 0x00, 0x00, 0x7f, 0x03, 0x6b, 0x65, 0x79, 0x06, 0x07, 0x62, 0x61, 0x64, 0xff, 0xff]),
);
expect(() => Object.fromEntries(MMKVParser.toStringMap(view).entries())).toThrow(/offset mismatch/i);
});

Binary file not shown.

Binary file not shown.