ProjectorRays as a WASM package!
A web example is available in example.html.
Install the projectorrays package from npm:
npm install projectorrays
or, if using yarn:
yarn install projectorrays
For web install the easiest way is to use the embedded version
import { DirectorFile } from "projectorrays/embedded";
// ....
const buffer = /* an ArrayBuffer */;
const directorFile = await DirectorFile.read(buffer);
// get chunks...
directorFile.dumpChunks()
// get unprotected version as buffer...
const buffer = directorFile.writeToBuffer()Note: this is only tested in node v22+.
For node, it is much the same but a slightly different entry point
import { DirectorFile } from "projectorrays/node"
const directorFile = await DirectorFile.readFromPath("example.dxr"); // or dcr, or dir, ...etc
// get chunks...
directorFile.dumpChunks()
// get unprotected version as buffer...
const buffer = directorFile.writeToBuffer()The DirectorFile class exposes the same core API in all environments
(projectorrays/embedded, projectorrays/web, projectorrays/node), with
extra filesystem helpers in Node.
DirectorFile.read(input, options?)->Promise<DirectorFile>Read a Director file from aUint8ArrayorArrayBuffer.DirectorFile.readFromPath(path, options?)(node only) ->Promise<DirectorFile>Read a Director file from disk.
Note: fourCC can be a 4-character string (e.g. "CASt") or a numeric fourCC code.
The numeric form is useful when you already have the 32-bit value from another parser or are working directly with chunk tables.
chunkExists(fourCC, chunkId)->booleanCheck whether a chunk exists by fourCC and chunkId.getChunk(fourCC, chunkId)->DirectorChunk | nullFetch a chunk's raw bytes.dumpChunks()->DirectorChunk[]Dump all chunks as raw bytes.dumpJSON()->DirectorChunkJSON[]Dump all chunks as JSON when available.size()->numberTotal size in bytes.isCast()->booleanWhether the file is a cast.
getScript(id)->DirectorScriptDetail | nullFetch a specific script entry.dumpScripts()->DirectorScriptDumpDump script metadata, source, and bytecode.
writeToBuffer()->Uint8ArrayWrite an unprotected version to a buffer.writeToFile(path)(node only) ->voidWrite the unprotected version to disk.destroy()->voidRelease WASM resources. The instance should not be used afterwards.
Note: We use Vite for our package.
Firstly, fetch the git sub modules.
Then, install dependencies using yarn v4
yarn install
Next, build mpg123:
make wasm-mpg123
Now we can build the wasm package:
make wasm
Finally, build the javascript package:
yarn build