diff --git a/README.md b/README.md index 01a9293..93b99e9 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,49 @@ npm i @pretendonetwork/nintendo-files ``` +## Usage +This package makes use of the [`"exports"` entry point](https://nodejs.org/api/packages.html#package-entry-points). Ensure your `tsconfig.json` is configured for this. + +Each file type may be imported both individually through separate import paths, or as named exports from the package root. + +```ts +import BYAML from '@pretendonetwork/nintendo-files/byaml'; +import BYML from '@pretendonetwork/nintendo-files/byml'; // Alias of byaml export +import Certificate from '@pretendonetwork/nintendo-files/certificate'; +import CIA from '@pretendonetwork/nintendo-files/cia'; +import MSBT from '@pretendonetwork/nintendo-files/msbt'; +import SMDH from '@pretendonetwork/nintendo-files/smdh'; +import Ticket from '@pretendonetwork/nintendo-files/ticket'; +import TMD from '@pretendonetwork/nintendo-files/tmd'; + +import { + BYAML, + BYML, // Alias of byaml export + Certificate, + CIA, + MSBT, + SMDH, + Ticket, + TMD +} from '@pretendonetwork/nintendo-files'; +``` + +In order to parse each file, call one of the provided parser methods. Methods exist both as instance and static methods for convenience. Each method is designed for parse the data from various data sources. Each class has the same common parser methods. For file specific methods and fields, see the classes type defs. + +```ts +import CIA from '@pretendonetwork/nintendo-files/cia'; + +let cia: CIA; + +cia = CIA.fromFile(fs.openSync('./nimbus.cia')); // Open file `fd` +cia = CIA.fromFile('./nimbus.cia'); // File path on disk +cia = CIA.fromBuffer(Buffer.from('...')); // Data as a buffer +cia = CIA.fromString('...'); // Base64 encoded data string +cia = CIA.fromFileStream(stream); // Mostly used for internal use. Accepts a FileStream from this library +``` + +Some classes support encoding the data back into a buffer. This is done through a `bytes()` method on each class. See below for a list of file type support. + ## Supported files (parsing) - [x] CIA. Does not decrypt contents - [x] Certificates. Signature verification works, just not on illegitimate signatures (homebrew, forged tickets, etc) diff --git a/package.json b/package.json index fd4cf42..b359a1c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@pretendonetwork/nintendo-files", - "version": "1.0.0", + "version": "1.0.2", "description": "TypeScript library for interacting with several Nintendo file formats across various consoles.", "scripts": { "lint": "npx eslint .", @@ -23,6 +23,9 @@ "image-encode": "^1.3.1", "node-rsa": "^1.1.1" }, + "files": [ + "dist" + ], "exports": { ".": { "import": "./dist/index.js",