UNPKG

@shockpkg/ria-packager

Version:

Package for creating Adobe AIR packages

269 lines (268 loc) 7.59 kB
import { SecurityKeystore } from './security/keystore.ts'; import { Signature } from './signature.ts'; import { Hasher } from './hasher.ts'; /** * Options for adding resources. */ export interface IPackagerResourceOptions { /** * Mark file as executable. */ executable?: boolean | null; /** * Specific file modification time. */ mtime?: Date | null; } /** * Packager object. */ export declare abstract class Packager { /** * Make a debug build. */ debug: boolean; /** * Keystore object to use for signing. */ keystore: Readonly<SecurityKeystore> | null; /** * Timestamp URL. */ timestampUrl: string | null; /** * Application descriptor file data. */ descriptorData: string | Readonly<Uint8Array> | (() => Readonly<string | Uint8Array>) | (() => Promise<Readonly<string | Uint8Array>>) | null; /** * Application descriptor file path. */ descriptorFile: string | null; /** * File and directory names to exclude when added a directory. */ excludes: RegExp[]; /** * Set the nobrowse option on mounted disk images. */ nobrowse: boolean; /** * Output path. */ readonly path: string; /** * Open flag. */ protected _isOpen: boolean; /** * Adding a resource flag. */ protected _isAddingResource: boolean; /** * Hasher object. */ protected _hasher: Hasher; /** * Signature object. */ protected _signature: Signature | null; /** * Packager constructor. * * @param path Output path. */ constructor(path: string); /** * Check if output open. * * @returns Returns true if open, else false. */ get isOpen(): boolean; /** * Open with application descriptor XML data. */ open(): Promise<void>; /** * Close output. */ close(): Promise<void>; /** * Run asyncronous function with automatic open and close. * * @param func Async function. * @returns Return value of the async function. */ write<T>(func: (self: this) => Promise<T>): Promise<T>; /** * Check if name is excluded file. * * @param name File name. * @returns Returns true if excluded, else false. */ isExcludedFile(name: string): boolean; /** * Add resource with file. * * @param source File path. * @param destination Packaged file relative destination. * @param options Resource options. */ addResourceFile(source: string, destination?: string | null, options?: Readonly<IPackagerResourceOptions> | null): Promise<void>; /** * Add resource with directory. * Walks the directory looking for files to add, skips excluded file names. * * @param source Directory path. * @param destination Packaged directory relative destination. * @param options Resource options. */ addResourceDirectory(source: string, destination?: string | null, options?: Readonly<IPackagerResourceOptions> | null): Promise<void>; /** * Add resource with data. * * @param destination Packaged file relative destination. * @param data Resource data. * @param options Resource options. */ addResource(destination: string, data: Readonly<Uint8Array>, options?: Readonly<IPackagerResourceOptions> | null): Promise<void>; /** * Create Hasher object. * * @returns Hasher object. */ protected _createHasher(): Hasher; /** * Create Signature object. * * @returns Hasher object. */ protected _createSignature(): Signature; /** * Path of the mimetype meta resource. * * @returns Resource path. */ protected get _metaResourceMimetypePath(): string; /** * Path of the application meta resource. * * @returns Resource path. */ protected get _metaResourceApplicationPath(): string; /** * Path of the hash meta resource. * * @returns Resource path. */ protected get _metaResourceHashPath(): string; /** * Path of the debug meta resource. * * @returns Resource path. */ protected get _metaResourceDebugPath(): string; /** * Path of the signatures meta resource. * * @returns Resource path. */ protected get _metaResourceSignaturesPath(): string; /** * Get application descriptor data or throw. * * @returns Application descriptor XML data. */ protected _getDescriptorData(): Promise<Readonly<Uint8Array<ArrayBufferLike>>>; /** * Get encoded mimetype data. * * @returns Mimetype data. */ protected _getMimetypeData(): Uint8Array<ArrayBufferLike>; /** * Get the keystore object. * * @returns Keystore object. */ protected _getKeystore(): Readonly<SecurityKeystore>; /** * Add resource with data, with options controlling hashing and signing. * * @param destination Packaged file relative destination. * @param data Resource data. * @param options Resource options. * @param hashed This file is hashed. * @param signed This file is signed. */ protected _addResource(destination: string, data: Readonly<Uint8Array>, options: Readonly<IPackagerResourceOptions>, hashed: boolean, signed: boolean): Promise<void>; /** * Add meta resources start. * * @param applicationData XML data. */ protected _addMetaResourcesStart(applicationData: Readonly<Uint8Array>): Promise<void>; /** * Add meta resources end. */ protected _addMetaResourcesEnd(): Promise<void>; /** * Add meta resource for the mimetype. */ protected _addMetaResourceMimetype(): Promise<void>; /** * Add meta resource for the application descriptor. * * @param applicationData The application descriptor data. */ protected _addMetaResourceApplication(applicationData: Readonly<Uint8Array>): Promise<void>; /** * Add meta resource for the hash (needs updating on close). */ protected _addMetaResourceHash(): Promise<void>; /** * Add meta resource for debug. */ protected _addMetaResourceDebug(): Promise<void>; /** * Add resource for signatures. */ protected _addMetaResourceSignatures(): Promise<void>; /** * Init application info from descriptor data. * * @param applicationData The application descriptor data. */ protected _applicationInfoInit(applicationData: Readonly<Uint8Array>): void; /** * Clear application info from descriptor data. */ protected _applicationInfoClear(): void; /** * Package mimetype. * * @returns Mimetype string. */ abstract get mimetype(): string; /** * Package signed. * * @returns Boolean for if package is signed or not. */ abstract get signed(): boolean; /** * Open implementation. */ protected abstract _open(): Promise<void>; /** * Close implementation. */ protected abstract _close(): Promise<void>; /** * Write resource with data implementation. * * @param destination Packaged file relative destination. * @param data Resource data. * @param options Resource options. */ protected abstract _writeResource(destination: string, data: Readonly<Uint8Array>, options: Readonly<IPackagerResourceOptions>): Promise<void>; }