nitro-patcher 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -0
- package/dist/browser.d.ts +25 -0
- package/dist/browser.js +82 -3
- package/dist/browser.js.map +3 -3
- package/dist/{chunk-L7ZM4LLP.js → chunk-ZY3OSZCA.js} +76 -2
- package/dist/{chunk-L7ZM4LLP.js.map → chunk-ZY3OSZCA.js.map} +1 -1
- package/dist/cli.js +104 -22
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +14 -2
- package/dist/nitro-patch-helper.d.ts +35 -1
- package/dist/nitro-patch-helper.js +15 -3
- package/package.json +4 -1
- package/src/browser.ts +43 -2
- package/src/cli.ts +116 -20
- package/src/nitro-patch-helper.ts +120 -1
package/README.md
CHANGED
package/dist/browser.d.ts
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
+
export interface PatchMetadata {
|
|
2
|
+
id?: string;
|
|
3
|
+
author?: string;
|
|
4
|
+
name?: string;
|
|
5
|
+
homepage?: string;
|
|
6
|
+
version?: string;
|
|
7
|
+
isBeta?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export interface PatchReadme {
|
|
10
|
+
format: 'markdown' | 'plaintext';
|
|
11
|
+
content: string;
|
|
12
|
+
}
|
|
13
|
+
export interface PatchInfo {
|
|
14
|
+
metadata: PatchMetadata | null;
|
|
15
|
+
readme: PatchReadme | null;
|
|
16
|
+
}
|
|
1
17
|
export interface BrowserPatchOptions {
|
|
2
18
|
maxOutputSize?: number;
|
|
3
19
|
maxWindowSize?: number;
|
|
@@ -26,8 +42,17 @@ export interface RomInfo {
|
|
|
26
42
|
export declare const inspectRom: (bytes: Uint8Array) => RomInfo;
|
|
27
43
|
/** Synchronous CPU work; call in a Web Worker for responsive browser UIs. */
|
|
28
44
|
export declare const patchBuffer: (original: Uint8Array, archive: Uint8Array, options?: BrowserPatchOptions) => BrowserPatchResult;
|
|
45
|
+
/** Read and validate metadata.json from a patch package entirely in memory. */
|
|
46
|
+
export declare const readPatchMetadata: (archive: Uint8Array, options?: BrowserPatchOptions) => PatchMetadata | null;
|
|
47
|
+
/** Read a root README.md or README.txt from a patch package entirely in memory. */
|
|
48
|
+
export declare const readPatchReadme: (archive: Uint8Array, options?: BrowserPatchOptions) => PatchReadme | null;
|
|
49
|
+
/** Read metadata and README content while parsing the patch package only once. */
|
|
50
|
+
export declare const readPatchInfo: (archive: Uint8Array, options?: BrowserPatchOptions) => PatchInfo;
|
|
29
51
|
export declare const PatchHelper: Readonly<{
|
|
30
52
|
patchBuffer: (original: Uint8Array, archive: Uint8Array, options?: BrowserPatchOptions) => BrowserPatchResult;
|
|
53
|
+
readPatchInfo: (archive: Uint8Array, options?: BrowserPatchOptions) => PatchInfo;
|
|
54
|
+
readPatchMetadata: (archive: Uint8Array, options?: BrowserPatchOptions) => PatchMetadata | null;
|
|
55
|
+
readPatchReadme: (archive: Uint8Array, options?: BrowserPatchOptions) => PatchReadme | null;
|
|
31
56
|
}>;
|
|
32
57
|
export declare const NitroHelper: Readonly<{
|
|
33
58
|
inspectRom: (bytes: Uint8Array) => RomInfo;
|
package/dist/browser.js
CHANGED
|
@@ -4531,6 +4531,65 @@ var PatchReturnValue = Object.freeze({
|
|
|
4531
4531
|
MD5_MISMATCH: "MD5_MISMATCH"
|
|
4532
4532
|
});
|
|
4533
4533
|
var md52 = (data) => hashDigest("md5", data).toString("hex");
|
|
4534
|
+
var invalidMetadata = (message) => {
|
|
4535
|
+
console.warn(`\u5FFD\u7565 metadata.json\uFF1A${message}`);
|
|
4536
|
+
return null;
|
|
4537
|
+
};
|
|
4538
|
+
var invalidMetadataField = (field2, message) => {
|
|
4539
|
+
console.warn(`\u5FFD\u7565 metadata.json \u7684 ${field2}\uFF1A${message}`);
|
|
4540
|
+
};
|
|
4541
|
+
var readMetadata = (files) => {
|
|
4542
|
+
const file = files.get("metadata.json");
|
|
4543
|
+
if (!file) return null;
|
|
4544
|
+
let metadata;
|
|
4545
|
+
try {
|
|
4546
|
+
metadata = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(file));
|
|
4547
|
+
} catch (error) {
|
|
4548
|
+
return invalidMetadata(
|
|
4549
|
+
`\u683C\u5F0F\u9519\u8BEF\uFF0C\u53EF\u80FD\u662F\u56E0\u4E3A\u8865\u4E01\u5305\u5DF2\u635F\u574F\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
4550
|
+
);
|
|
4551
|
+
}
|
|
4552
|
+
if (!metadata || typeof metadata !== "object" || Array.isArray(metadata))
|
|
4553
|
+
return invalidMetadata("\u6839\u8282\u70B9\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
|
|
4554
|
+
const value = metadata;
|
|
4555
|
+
const result = {};
|
|
4556
|
+
for (const field2 of ["id", "author", "name", "homepage", "version"]) {
|
|
4557
|
+
if (typeof value[field2] === "string") result[field2] = value[field2];
|
|
4558
|
+
else invalidMetadataField(field2, "\u5FC5\u987B\u662F\u5B57\u7B26\u4E32\u3002");
|
|
4559
|
+
}
|
|
4560
|
+
if (typeof value.isBeta === "boolean") result.isBeta = value.isBeta;
|
|
4561
|
+
else invalidMetadataField("isBeta", "\u5FC5\u987B\u662F\u5E03\u5C14\u503C\u3002");
|
|
4562
|
+
return result;
|
|
4563
|
+
};
|
|
4564
|
+
var readReadme = (files) => {
|
|
4565
|
+
for (const [filename2, format] of [
|
|
4566
|
+
["README.md", "markdown"],
|
|
4567
|
+
["README.txt", "plaintext"]
|
|
4568
|
+
]) {
|
|
4569
|
+
const file = files.get(filename2.toLowerCase());
|
|
4570
|
+
if (!file) continue;
|
|
4571
|
+
try {
|
|
4572
|
+
return {
|
|
4573
|
+
format,
|
|
4574
|
+
content: new TextDecoder("utf-8", { fatal: true }).decode(file)
|
|
4575
|
+
};
|
|
4576
|
+
} catch (error) {
|
|
4577
|
+
console.warn(
|
|
4578
|
+
`\u5FFD\u7565 ${filename2}\uFF1A\u4E0D\u662F\u6709\u6548\u7684 UTF-8 \u6587\u672C\uFF1A${error instanceof Error ? error.message : String(error)}`
|
|
4579
|
+
);
|
|
4580
|
+
}
|
|
4581
|
+
}
|
|
4582
|
+
return null;
|
|
4583
|
+
};
|
|
4584
|
+
var readPatchMetadata = (patch, options = {}) => readMetadata(readZip(patch, options));
|
|
4585
|
+
var readPatchReadme = (patch, options = {}) => readReadme(readZip(patch, options));
|
|
4586
|
+
var readPatchInfo = (patch, options = {}) => {
|
|
4587
|
+
const files = readZip(patch, options);
|
|
4588
|
+
return { metadata: readMetadata(files), readme: readReadme(files) };
|
|
4589
|
+
};
|
|
4590
|
+
var readPatchMetadataFile = async (patchPath, options = {}) => readPatchMetadata(await readFile(patchPath), options);
|
|
4591
|
+
var readPatchReadmeFile = async (patchPath, options = {}) => readPatchReadme(await readFile(patchPath), options);
|
|
4592
|
+
var readPatchInfoFile = async (patchPath, options = {}) => readPatchInfo(await readFile(patchPath), options);
|
|
4534
4593
|
var patchBuffer = (original, patch, options = {}) => {
|
|
4535
4594
|
const input = bytes(original, "original ROM");
|
|
4536
4595
|
const patches = readZip(patch, options);
|
|
@@ -4572,7 +4631,16 @@ var patchIt = async (originalPath, patchPath, options = {}) => {
|
|
|
4572
4631
|
const [original, patch] = await Promise.all([readFile(originalPath), readFile(patchPath)]);
|
|
4573
4632
|
return patchBuffer(original, patch, options);
|
|
4574
4633
|
};
|
|
4575
|
-
var PatchHelper = Object.freeze({
|
|
4634
|
+
var PatchHelper = Object.freeze({
|
|
4635
|
+
patchBuffer,
|
|
4636
|
+
patchIt,
|
|
4637
|
+
readPatchInfo,
|
|
4638
|
+
readPatchInfoFile,
|
|
4639
|
+
readPatchMetadata,
|
|
4640
|
+
readPatchMetadataFile,
|
|
4641
|
+
readPatchReadme,
|
|
4642
|
+
readPatchReadmeFile
|
|
4643
|
+
});
|
|
4576
4644
|
|
|
4577
4645
|
// src/browser.ts
|
|
4578
4646
|
var inspectRom = (bytes2) => {
|
|
@@ -4604,13 +4672,24 @@ var patchBuffer2 = (original, archive, options = {}) => {
|
|
|
4604
4672
|
outputMd5: result.outputMd5
|
|
4605
4673
|
};
|
|
4606
4674
|
};
|
|
4607
|
-
var
|
|
4675
|
+
var readPatchMetadata2 = (archive, options = {}) => readPatchMetadata(archive, options);
|
|
4676
|
+
var readPatchReadme2 = (archive, options = {}) => readPatchReadme(archive, options);
|
|
4677
|
+
var readPatchInfo2 = (archive, options = {}) => readPatchInfo(archive, options);
|
|
4678
|
+
var PatchHelper2 = Object.freeze({
|
|
4679
|
+
patchBuffer: patchBuffer2,
|
|
4680
|
+
readPatchInfo: readPatchInfo2,
|
|
4681
|
+
readPatchMetadata: readPatchMetadata2,
|
|
4682
|
+
readPatchReadme: readPatchReadme2
|
|
4683
|
+
});
|
|
4608
4684
|
var NitroHelper = Object.freeze({ inspectRom });
|
|
4609
4685
|
export {
|
|
4610
4686
|
NitroHelper,
|
|
4611
4687
|
PatchHelper2 as PatchHelper,
|
|
4612
4688
|
inspectRom,
|
|
4613
|
-
patchBuffer2 as patchBuffer
|
|
4689
|
+
patchBuffer2 as patchBuffer,
|
|
4690
|
+
readPatchInfo2 as readPatchInfo,
|
|
4691
|
+
readPatchMetadata2 as readPatchMetadata,
|
|
4692
|
+
readPatchReadme2 as readPatchReadme
|
|
4614
4693
|
};
|
|
4615
4694
|
/*! For license information please see browser.js.LEGAL.txt */
|
|
4616
4695
|
//# sourceMappingURL=browser.js.map
|