diff --git a/codecs/codecs.js b/codecs/codecs.js index 7c8a1d4..00b5735 100644 --- a/codecs/codecs.js +++ b/codecs/codecs.js @@ -12,7 +12,7 @@ */ /** - * @typdef ProbeStream ffprobe -show_streams -print_format json. Only the fields we care about. + * @typedef ProbeStream ffprobe -show_streams -print_format json. Only the fields we care about. * @property {number} index * @property {string} codec_name * @property {string} codec_long_name diff --git a/image/webp-shim/webp-shim.js b/image/webp-shim/webp-shim.js index 0878576..f9f607b 100644 --- a/image/webp-shim/webp-shim.js +++ b/image/webp-shim/webp-shim.js @@ -47,7 +47,7 @@ function loadWebPShimApi() { } /** - * @param {ArrayBuffer|TypedArray} webpBuffer The byte array containing the WebP image bytes. + * @param {ArrayBuffer|Uint8Array} webpBuffer The byte array containing the WebP image bytes. * @returns {Promise} A Promise resolving to a byte array containing the PNG bytes. */ export function convertWebPtoPNG(webpBuffer) { @@ -76,7 +76,7 @@ export function convertWebPtoPNG(webpBuffer) { } /** - * @param {ArrayBuffer|TypedArray} webpBuffer The byte array containing the WebP image bytes. + * @param {ArrayBuffer|Uint8Array} webpBuffer The byte array containing the WebP image bytes. * @returns {Promise} A Promise resolving to a byte array containing the JPG bytes. */ export function convertWebPtoJPG(webpBuffer) { diff --git a/index.js b/index.js index 2bfa25b..e1b106b 100644 --- a/index.js +++ b/index.js @@ -6,11 +6,22 @@ * Copyright(c) 2020 Google Inc. */ +/** + * @typedef {import('./codecs/codecs.js').ProbeStream} ProbeStream + */ +/** + * @typedef {import('./codecs/codecs.js').ProbeFormat} ProbeFormat + */ +/** + * @typedef {import('./codecs/codecs.js').ProbeInfo} ProbeInfo + */ + export { UnarchiveEvent, UnarchiveEventType, UnarchiveInfoEvent, UnarchiveErrorEvent, UnarchiveStartEvent, UnarchiveFinishEvent, UnarchiveProgressEvent, UnarchiveExtractEvent, Unarchiver, Unzipper, Unrarrer, Untarrer, getUnarchiver } from './archive/archive.js'; +export { getFullMIMEString, getShortMIMEString } from './codecs/codecs.js'; export { findMimeType } from './file/sniffer.js'; export { convertWebPtoPNG, convertWebPtoJPG } from './image/webp-shim/webp-shim.js'; export { BitStream } from './io/bitstream.js'; diff --git a/package.json b/package.json index fd98dbf..6a736cf 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@codedread/bitjs", - "version": "1.0.1", + "version": "1.0.2", "description": "Binary Tools for JavaScript", "homepage": "https://github.com/codedread/bitjs", "author": "Jeff Schiller", @@ -24,6 +24,7 @@ ], "main": "./index.js", "type": "module", + "types": "types/index.d.ts", "exports": "./index.js", "repository": { "type": "git", @@ -42,7 +43,8 @@ }, "devDependencies": { "chai": "^4.3.4", - "mocha": "^8.4.0" + "mocha": "^8.4.0", + "typescript": "^4.8.0" }, "dependencies": {} } diff --git a/tsconfig.json b/tsconfig.json new file mode 100644 index 0000000..8a871a8 --- /dev/null +++ b/tsconfig.json @@ -0,0 +1,22 @@ +{ + // Change this to match your project + "include": ["index.js"], + "exclude": [], + "compilerOptions": { + // Tells TypeScript to read JS files, as + // normally they are ignored as source files + "allowJs": true, + // Generate d.ts files + "declaration": true, + // This compiler run should + // only output d.ts files + "emitDeclarationOnly": true, + // Types should go into this directory. + // Removing this would place the .d.ts files + // next to the .js files + "outDir": "types", + // go to js file when using IDE functions like + // "Go to Definition" in VSCode + "declarationMap": true + } +} diff --git a/types/archive/archive.d.ts b/types/archive/archive.d.ts new file mode 100644 index 0000000..10d7710 --- /dev/null +++ b/types/archive/archive.d.ts @@ -0,0 +1,39 @@ +/** + * Factory method that creates an unarchiver based on the byte signature found + * in the arrayBuffer. + * @param {ArrayBuffer} ab The ArrayBuffer to unarchive. Note that this ArrayBuffer + * must not be referenced after calling this method, as the ArrayBuffer is marked + * as Transferable and sent to a Worker thread once start() is called. + * @param {Object|string} options An optional object of options, or a string + * representing where the path to the unarchiver script files. + * @returns {Unarchiver} + */ +export function getUnarchiver(ab: ArrayBuffer, options?: any | string): Unarchiver; +export class Unzipper extends UnzipperInternal { + constructor(ab: any, options: any); +} +export class Unrarrer extends UnrarrerInternal { + constructor(ab: any, options: any); +} +export class Untarrer extends UntarrerInternal { + constructor(ab: any, options: any); +} +export type UnarchivedFile = { + filename: string; + fileData: Uint8Array; +}; +import { Unarchiver } from "./decompress-internal.js"; +import { UnarchiveAppendEvent } from "./decompress-internal.js"; +import { UnarchiveErrorEvent } from "./decompress-internal.js"; +import { UnarchiveEvent } from "./decompress-internal.js"; +import { UnarchiveEventType } from "./decompress-internal.js"; +import { UnarchiveExtractEvent } from "./decompress-internal.js"; +import { UnarchiveFinishEvent } from "./decompress-internal.js"; +import { UnarchiveInfoEvent } from "./decompress-internal.js"; +import { UnarchiveProgressEvent } from "./decompress-internal.js"; +import { UnarchiveStartEvent } from "./decompress-internal.js"; +import { UnzipperInternal } from "./decompress-internal.js"; +import { UnrarrerInternal } from "./decompress-internal.js"; +import { UntarrerInternal } from "./decompress-internal.js"; +export { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType, UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent, UnarchiveProgressEvent, UnarchiveStartEvent, Unarchiver }; +//# sourceMappingURL=archive.d.ts.map \ No newline at end of file diff --git a/types/archive/archive.d.ts.map b/types/archive/archive.d.ts.map new file mode 100644 index 0000000..0ff66e4 --- /dev/null +++ b/types/archive/archive.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"archive.d.ts","sourceRoot":"","sources":["../../archive/archive.js"],"names":[],"mappings":"AA0EA;;;;;;;;;GASG;AACH,kCAPW,WAAW,YAGX,MAAO,MAAM,GAEX,UAAU,CAItB;AAxBD;IACE,mCAAgE;CACjE;AAED;IACE,mCAAgE;CACjE;AAED;IACE,mCAAgE;CACjE;;cAjCa,MAAM;cACN,UAAU"} \ No newline at end of file diff --git a/types/archive/decompress-internal.d.ts b/types/archive/decompress-internal.d.ts new file mode 100644 index 0000000..dba2bf9 --- /dev/null +++ b/types/archive/decompress-internal.d.ts @@ -0,0 +1,245 @@ +/** + * Factory method that creates an unarchiver based on the byte signature found + * in the arrayBuffer. + * @param {ArrayBuffer} ab + * @param {Function(string):Worker} createWorkerFn A function that creates a Worker from a script file. + * @param {Object|string} options An optional object of options, or a string representing where + * the path to the unarchiver script files. + * @returns {Unarchiver} + */ +export function getUnarchiverInternal(ab: ArrayBuffer, createWorkerFn: any, options?: any | string): Unarchiver; +export namespace UnarchiveEventType { + const START: string; + const APPEND: string; + const PROGRESS: string; + const EXTRACT: string; + const FINISH: string; + const INFO: string; + const ERROR: string; +} +/** + * An unarchive event. + */ +export class UnarchiveEvent { + /** + * @param {string} type The event type. + */ + constructor(type: string); + /** + * The event type. + * @type {string} + */ + type: string; +} +/** + * Updates all Archiver listeners that an append has occurred. + */ +export class UnarchiveAppendEvent extends UnarchiveEvent { + /** + * @param {number} numBytes The number of bytes appended. + */ + constructor(numBytes: number); + /** + * The number of appended bytes. + * @type {number} + */ + numBytes: number; +} +/** + * Useful for passing info up to the client (for debugging). + */ +export class UnarchiveInfoEvent extends UnarchiveEvent { + /** + * The information message. + * @type {string} + */ + msg: string; +} +/** + * An unrecoverable error has occured. + */ +export class UnarchiveErrorEvent extends UnarchiveEvent { + /** + * The information message. + * @type {string} + */ + msg: string; +} +/** + * Start event. + */ +export class UnarchiveStartEvent extends UnarchiveEvent { + constructor(); +} +/** + * Finish event. + */ +export class UnarchiveFinishEvent extends UnarchiveEvent { + /** + * @param {Object} metadata A collection fo metadata about the archive file. + */ + constructor(metadata?: any); + metadata: any; +} +/** + * Progress event. + */ +export class UnarchiveProgressEvent extends UnarchiveEvent { + /** + * @param {string} currentFilename + * @param {number} currentFileNumber + * @param {number} currentBytesUnarchivedInFile + * @param {number} currentBytesUnarchived + * @param {number} totalUncompressedBytesInArchive + * @param {number} totalFilesInArchive + * @param {number} totalCompressedBytesRead + */ + constructor(currentFilename: string, currentFileNumber: number, currentBytesUnarchivedInFile: number, currentBytesUnarchived: number, totalUncompressedBytesInArchive: number, totalFilesInArchive: number, totalCompressedBytesRead: number); + currentFilename: string; + currentFileNumber: number; + currentBytesUnarchivedInFile: number; + totalFilesInArchive: number; + currentBytesUnarchived: number; + totalUncompressedBytesInArchive: number; + totalCompressedBytesRead: number; +} +/** + * Extract event. + */ +export class UnarchiveExtractEvent extends UnarchiveEvent { + /** + * @param {UnarchivedFile} unarchivedFile + */ + constructor(unarchivedFile: UnarchivedFile); + /** + * @type {UnarchivedFile} + */ + unarchivedFile: UnarchivedFile; +} +/** + * Base class for all Unarchivers. + * TODO: When EventTarget constructors are broadly supported, make this extend + * EventTarget and remove event listener code. + * https://caniuse.com/#feat=mdn-api_eventtarget_eventtarget + */ +export class Unarchiver { + /** + * @param {ArrayBuffer} arrayBuffer The Array Buffer. Note that this ArrayBuffer must not be + * referenced once it is sent to the Unarchiver, since it is marked as Transferable and sent + * to the Worker. + * @param {Function(string):Worker} createWorkerFn A function that creates a Worker from a script file. + * @param {Object|string} options An optional object of options, or a string representing where + * the BitJS files are located. The string version of this argument is deprecated. + * Available options: + * 'pathToBitJS': A string indicating where the BitJS files are located. + * 'debug': A boolean where true indicates that the archivers should log debug output. + */ + constructor(arrayBuffer: ArrayBuffer, createWorkerFn: any, options?: any | string); + /** + * The ArrayBuffer object. + * @type {ArrayBuffer} + * @protected + */ + protected ab: ArrayBuffer; + /** + * A factory method that creates a Worker that does the unarchive work. + * @type {Function(string): Worker} + * @private + */ + private createWorkerFn_; + /** + * The path to the BitJS files. + * @type {string} + * @private + */ + private pathToBitJS_; + /** + * @orivate + * @type {boolean} + */ + debugMode_: boolean; + /** + * A map from event type to an array of listeners. + * @private + * @type {Map.} + */ + private listeners_; + /** + * Private web worker initialized during start(). + * @private + * @type {Worker} + */ + private worker_; + /** + * This method must be overridden by the subclass to return the script filename. + * @returns {string} The MIME type of the archive. + * @protected. + */ + protected getMIMEType(): string; + /** + * This method must be overridden by the subclass to return the script filename. + * @returns {string} The script filename. + * @protected. + */ + protected getScriptFileName(): string; + /** + * Adds an event listener for UnarchiveEvents. + * + * @param {string} Event type. + * @param {function} An event handler function. + */ + addEventListener(type: any, listener: any): void; + /** + * Removes an event listener. + * + * @param {string} Event type. + * @param {EventListener|function} An event listener or handler function. + */ + removeEventListener(type: any, listener: any): void; + /** + * Create an UnarchiveEvent out of the object sent back from the Worker. + * @param {Object} obj + * @returns {UnarchiveEvent} + * @private + */ + private createUnarchiveEvent_; + /** + * Receive an event and pass it to the listener functions. + * + * @param {Object} obj + * @private + */ + private handleWorkerEvent_; + /** + * Starts the unarchive in a separate Web Worker thread and returns immediately. + */ + start(): void; + /** + * Adds more bytes to the unarchiver's Worker thread. + * @param {ArrayBuffer} ab The ArrayBuffer with more bytes in it. If opt_transferable is + * set to true, this ArrayBuffer must not be referenced after calling update(), since it + * is marked as Transferable and sent to the Worker. + * @param {boolean=} opt_transferable Optional boolean whether to mark this ArrayBuffer + * as a Tranferable object, which means it can no longer be referenced outside of + * the Worker thread. + */ + update(ab: ArrayBuffer, opt_transferable?: boolean | undefined): void; + /** + * Terminates the Web Worker for this Unarchiver and returns immediately. + */ + stop(): void; +} +export class UnzipperInternal extends Unarchiver { + constructor(arrayBuffer: any, createWorkerFn: any, options: any); +} +export class UnrarrerInternal extends Unarchiver { + constructor(arrayBuffer: any, createWorkerFn: any, options: any); +} +export class UntarrerInternal extends Unarchiver { + constructor(arrayBuffer: any, createWorkerFn: any, options: any); +} +export type UnarchivedFile = { + filename: string; + fileData: Uint8Array; +}; +//# sourceMappingURL=decompress-internal.d.ts.map \ No newline at end of file diff --git a/types/archive/decompress-internal.d.ts.map b/types/archive/decompress-internal.d.ts.map new file mode 100644 index 0000000..9fed7cc --- /dev/null +++ b/types/archive/decompress-internal.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"decompress-internal.d.ts","sourceRoot":"","sources":["../../archive/decompress-internal.js"],"names":[],"mappings":"AAgbA;;;;;;;;GAQG;AACF,0CANU,WAAW,iCAEX,MAAO,MAAM,GAEX,UAAU,CAkBtB;;;;;;;;;;AAzaD;;GAEG;AACF;IACC;;OAEG;IACH,kBAFW,MAAM,EAQhB;IALC;;;OAGG;IACH,MAFU,MAAM,CAEA;CAEnB;AAED;;GAEG;AACF;IACC;;OAEG;IACH,sBAFW,MAAM,EAUhB;IALC;;;OAGG;IACH,UAFU,MAAM,CAEQ;CAE3B;AAED;;GAEG;AACH;IAOI;;;OAGG;IACH,KAFU,MAAM,CAEF;CAEjB;AAED;;GAEG;AACH;IAOI;;;OAGG;IACH,KAFU,MAAM,CAEF;CAEjB;AAED;;GAEG;AACH;IACE,cAEC;CACF;AAED;;GAEG;AACH;IACE;;OAEG;IACH,4BAGC;IADC,cAAwB;CAE3B;AAED;;GAEG;AACH;IACE;;;;;;;;OAQG;IACH,6BARW,MAAM,qBACN,MAAM,gCACN,MAAM,0BACN,MAAM,mCACN,MAAM,uBACN,MAAM,4BACN,MAAM,EAchB;IAPC,wBAAsC;IACtC,0BAA0C;IAC1C,qCAAgE;IAChE,4BAA8C;IAC9C,+BAAoD;IACpD,wCAAsE;IACtE,iCAAwD;CAE3D;AAED;;GAEG;AACH;IACE;;OAEG;IACH,4BAFW,cAAc,EASxB;IAJC;;OAEG;IACH,gBAFU,cAAc,CAEY;CAEvC;AAED;;;;;GAKG;AACF;IACC;;;;;;;;;;OAUG;IACH,yBAVW,WAAW,iCAIX,MAAO,MAAM,EAwDvB;IA3CC;;;;OAIG;IACH,cAHU,WAAW,CAGA;IAErB;;;;OAIG;IACH,wBAAqC;IAErC;;;;OAIG;IACH,qBAA8C;IAE9C;;;OAGG;IACH,YAFU,OAAO,CAEkB;IAEnC;;;;OAIG;IACH,mBAAoB;IAKpB;;;;OAIG;IACH,gBAAmB;IAGrB;;;;OAIG;IACH,yBAHa,MAAM,CAKlB;IAED;;;;OAIG;IACH,+BAHa,MAAM,CAKlB;IAED;;;;;OAKG;IACH,iDAMC;IAED;;;;;OAKG;IACH,oDAOC;IAED;;;;;OAKG;IACH,8BAsBC;IAED;;;;;OAKG;IACH,2BAYC;IAED;;OAEG;IACH,cA2BC;IAID;;;;;;;;OAQG;IACH,WAPW,WAAW,qBAGX,OAAO,oBAkBjB;IAED;;OAEG;IACH,aAIC;CACF;AAED;IACE,iEAEC;CAIF;AAED;IACE,iEAEC;CAIF;AAED;IACE,iEAEC;CAIF;;cA/Za,MAAM;cACN,UAAU"} \ No newline at end of file diff --git a/types/codecs/codecs.d.ts b/types/codecs/codecs.d.ts new file mode 100644 index 0000000..df42b8b --- /dev/null +++ b/types/codecs/codecs.d.ts @@ -0,0 +1,97 @@ +/** + * This module helps interpret ffprobe -print_format json output. + * Its coverage is pretty sparse right now, so send me pull requests! + */ +/** + * @typedef ProbeStream ffprobe -show_streams -print_format json. Only the fields we care about. + * @property {number} index + * @property {string} codec_name + * @property {string} codec_long_name + * @property {string} profile + * @property {string} codec_type Either 'audio' or 'video'. + * @property {string} codec_tag_string + * @property {string} id + * @property {number?} level + * @property {number?} width + * @property {number?} height + * @property {string} r_frame_rate Like "60000/1001" + */ +/** + * @typedef ProbeFormat ffprobe -show_format -print_format json. Only the fields we care about. + * @property {string} filename + * @property {string} format_name + * @property {string} duration Number of seconds, as a string like "473.506367". + * @property {string} size Number of bytes, as a string. + * @property {string} bit_rate Bit rate, as a string. + */ +/** + * @typedef ProbeInfo ffprobe -show_format -show_streams -print_format json + * @property {ProbeStream[]} streams + * @property {ProbeFormat} format + */ +/** + * TODO: Reconcile this with file/sniffer.js findMimeType() which does signature matching. + * @param {ProbeInfo} info + * @returns {string} + */ +export function getShortMIMEString(info: ProbeInfo): string; +/** + * Accepts the ffprobe JSON output and returns an ISO MIME string with parameters (RFC6381), such + * as 'video/mp4; codecs="avc1.4D4028, mp4a.40.2"'. This string should be suitable to be used on + * the server as the Content-Type header of a media stream which can subsequently be used on the + * client as the type value of a SourceBuffer object `mediaSource.addSourceBuffer(contentType)`. + * NOTE: For now, this method fails hard (throws an error) when it encounters a format/codec it + * does not recognize. Please file a bug or send a PR. + * @param {ProbeInfo} info + * @returns {string} + */ +export function getFullMIMEString(info: ProbeInfo): string; +/** + * ffprobe -show_streams -print_format json. Only the fields we care about. + */ +export type ProbeStream = { + index: number; + codec_name: string; + codec_long_name: string; + profile: string; + /** + * Either 'audio' or 'video'. + */ + codec_type: string; + codec_tag_string: string; + id: string; + level: number | null; + width: number | null; + height: number | null; + /** + * Like "60000/1001" + */ + r_frame_rate: string; +}; +/** + * ffprobe -show_format -print_format json. Only the fields we care about. + */ +export type ProbeFormat = { + filename: string; + format_name: string; + /** + * Number of seconds, as a string like "473.506367". + */ + duration: string; + /** + * Number of bytes, as a string. + */ + size: string; + /** + * Bit rate, as a string. + */ + bit_rate: string; +}; +/** + * ffprobe -show_format -show_streams -print_format json + */ +export type ProbeInfo = { + streams: ProbeStream[]; + format: ProbeFormat; +}; +//# sourceMappingURL=codecs.d.ts.map \ No newline at end of file diff --git a/types/codecs/codecs.d.ts.map b/types/codecs/codecs.d.ts.map new file mode 100644 index 0000000..3dc01dc --- /dev/null +++ b/types/codecs/codecs.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"codecs.d.ts","sourceRoot":"","sources":["../../codecs/codecs.js"],"names":[],"mappings":"AAQA;;;GAGG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AAEH;;;;GAIG;AAEH;;;;GAIG;AACH,yCAHW,SAAS,GACP,MAAM,CAuClB;AAED;;;;;;;;;GASG;AACH,wCAHW,SAAS,GACP,MAAM,CAyBlB;;;;;WAzGa,MAAM;gBACN,MAAM;qBACN,MAAM;aACN,MAAM;;;;gBACN,MAAM;sBACN,MAAM;QACN,MAAM;WACN,MAAM;WACN,MAAM;YACN,MAAM;;;;kBACN,MAAM;;;;;;cAKN,MAAM;iBACN,MAAM;;;;cACN,MAAM;;;;UACN,MAAM;;;;cACN,MAAM;;;;;;aAKN,WAAW,EAAE;YACb,WAAW"} \ No newline at end of file diff --git a/types/file/sniffer.d.ts b/types/file/sniffer.d.ts new file mode 100644 index 0000000..76e10af --- /dev/null +++ b/types/file/sniffer.d.ts @@ -0,0 +1,12 @@ +/** + * This function initializes the byte tree. It is lazily called upon findMimeType(), but if you care + * about when the tree initializes (like in startup, etc), you can call it yourself here. + */ +export function initialize(): void; +/** + * Finds the likely MIME type represented by the ArrayBuffer. + * @param {ArrayBuffer} ab + * @returns {string} The MIME type of the buffer, or undefined. + */ +export function findMimeType(ab: ArrayBuffer): string; +//# sourceMappingURL=sniffer.d.ts.map \ No newline at end of file diff --git a/types/file/sniffer.d.ts.map b/types/file/sniffer.d.ts.map new file mode 100644 index 0000000..9b08e38 --- /dev/null +++ b/types/file/sniffer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"sniffer.d.ts","sourceRoot":"","sources":["../../file/sniffer.js"],"names":[],"mappings":"AA+DA;;;GAGG;AACH,mCAiCC;AAED;;;;GAIG;AACH,iCAHW,WAAW,GACT,MAAM,CAqBlB"} \ No newline at end of file diff --git a/types/image/webp-shim/webp-shim.d.ts b/types/image/webp-shim/webp-shim.d.ts new file mode 100644 index 0000000..b6584f7 --- /dev/null +++ b/types/image/webp-shim/webp-shim.d.ts @@ -0,0 +1,11 @@ +/** + * @param {ArrayBuffer|Uint8Array} webpBuffer The byte array containing the WebP image bytes. + * @returns {Promise} A Promise resolving to a byte array containing the PNG bytes. + */ +export function convertWebPtoPNG(webpBuffer: ArrayBuffer | Uint8Array): Promise; +/** + * @param {ArrayBuffer|Uint8Array} webpBuffer The byte array containing the WebP image bytes. + * @returns {Promise} A Promise resolving to a byte array containing the JPG bytes. + */ +export function convertWebPtoJPG(webpBuffer: ArrayBuffer | Uint8Array): Promise; +//# sourceMappingURL=webp-shim.d.ts.map \ No newline at end of file diff --git a/types/image/webp-shim/webp-shim.d.ts.map b/types/image/webp-shim/webp-shim.d.ts.map new file mode 100644 index 0000000..75b4874 --- /dev/null +++ b/types/image/webp-shim/webp-shim.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"webp-shim.d.ts","sourceRoot":"","sources":["../../../image/webp-shim/webp-shim.js"],"names":[],"mappings":"AAgDA;;;GAGG;AACH,6CAHW,WAAW,GAAC,UAAU,GACpB,QAAQ,WAAW,CAAC,CAyBhC;AAED;;;GAGG;AACH,6CAHW,WAAW,GAAC,UAAU,GACpB,QAAQ,WAAW,CAAC,CAyBhC"} \ No newline at end of file diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..e6853b8 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,11 @@ +export { findMimeType } from "./file/sniffer.js"; +export { BitStream } from "./io/bitstream.js"; +export { ByteBuffer } from "./io/bytebuffer.js"; +export { ByteStream } from "./io/bytestream.js"; +export type ProbeStream = import('./codecs/codecs.js').ProbeStream; +export type ProbeFormat = import('./codecs/codecs.js').ProbeFormat; +export type ProbeInfo = import('./codecs/codecs.js').ProbeInfo; +export { UnarchiveEvent, UnarchiveEventType, UnarchiveInfoEvent, UnarchiveErrorEvent, UnarchiveStartEvent, UnarchiveFinishEvent, UnarchiveProgressEvent, UnarchiveExtractEvent, Unarchiver, Unzipper, Unrarrer, Untarrer, getUnarchiver } from "./archive/archive.js"; +export { getFullMIMEString, getShortMIMEString } from "./codecs/codecs.js"; +export { convertWebPtoPNG, convertWebPtoJPG } from "./image/webp-shim/webp-shim.js"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/types/index.d.ts.map b/types/index.d.ts.map new file mode 100644 index 0000000..eec20b0 --- /dev/null +++ b/types/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.js"],"names":[],"mappings":";;;;0BASa,OAAO,oBAAoB,EAAE,WAAW;0BAGxC,OAAO,oBAAoB,EAAE,WAAW;wBAGxC,OAAO,oBAAoB,EAAE,SAAS"} \ No newline at end of file diff --git a/types/io/bitstream.d.ts b/types/io/bitstream.d.ts new file mode 100644 index 0000000..79fc223 --- /dev/null +++ b/types/io/bitstream.d.ts @@ -0,0 +1,87 @@ +export const BitStream: { + new (ab: ArrayBuffer, mtl: boolean, opt_offset: number, opt_length: number): { + /** + * The bytes in the stream. + * @type {Uint8Array} + * @private + */ + bytes: Uint8Array; + /** + * The byte in the stream that we are currently on. + * @type {Number} + * @private + */ + bytePtr: number; + /** + * The bit in the current byte that we will read next (can have values 0 through 7). + * @type {Number} + * @private + */ + bitPtr: number; + /** + * An ever-increasing number. + * @type {Number} + * @private + */ + bitsRead_: number; + peekBits: (n: number, opt_movePointers: any) => number; + /** + * Returns how many bites have been read in the stream since the beginning of time. + */ + getNumBitsRead(): number; + /** + * Returns how many bits are currently in the stream left to be read. + */ + getNumBitsLeft(): number; + /** + * byte0 byte1 byte2 byte3 + * 7......0 | 7......0 | 7......0 | 7......0 + * + * The bit pointer starts at least-significant bit (0) of byte0 and moves left until it reaches + * bit7 of byte0, then jumps to bit0 of byte1, etc. + * @param {number} n The number of bits to peek, must be a positive integer. + * @param {boolean=} movePointers Whether to move the pointer, defaults false. + * @returns {number} The peeked bits, as an unsigned number. + */ + peekBits_ltm(n: number, opt_movePointers: any): number; + /** + * byte0 byte1 byte2 byte3 + * 7......0 | 7......0 | 7......0 | 7......0 + * + * The bit pointer starts at bit7 of byte0 and moves right until it reaches + * bit0 of byte0, then goes to bit7 of byte1, etc. + * @param {number} n The number of bits to peek. Must be a positive integer. + * @param {boolean=} movePointers Whether to move the pointer, defaults false. + * @returns {number} The peeked bits, as an unsigned number. + */ + peekBits_mtl(n: number, opt_movePointers: any): number; + /** + * Peek at 16 bits from current position in the buffer. + * Bit at (bytePtr,bitPtr) has the highest position in returning data. + * Taken from getbits.hpp in unrar. + * TODO: Move this out of BitStream and into unrar. + */ + getBits(): number; + /** + * Reads n bits out of the stream, consuming them (moving the bit pointer). + * @param {number} n The number of bits to read. Must be a positive integer. + * @returns {number} The read bits, as an unsigned number. + */ + readBits(n: number): number; + /** + * This returns n bytes as a sub-array, advancing the pointer if movePointers + * is true. Only use this for uncompressed blocks as this throws away remaining + * bits in the current byte. + * @param {number} n The number of bytes to peek. Must be a positive integer. + * @param {boolean=} movePointers Whether to move the pointer, defaults false. + * @returns {Uint8Array} The subarray. + */ + peekBytes(n: number, opt_movePointers: any): Uint8Array; + /** + * @param {number} n The number of bytes to read. + * @returns {Uint8Array} The subarray. + */ + readBytes(n: number): Uint8Array; + }; +}; +//# sourceMappingURL=bitstream.d.ts.map \ No newline at end of file diff --git a/types/io/bitstream.d.ts.map b/types/io/bitstream.d.ts.map new file mode 100644 index 0000000..b81ff4a --- /dev/null +++ b/types/io/bitstream.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bitstream.d.ts","sourceRoot":"","sources":["../../io/bitstream.js"],"names":[],"mappings":"AACA;aAwBe,WAAW,OACX,OAAO;QAchB;;;;WAIG;eAFO,UAAU;QAKpB;;;;WAIG;;QAGH;;;;WAIG;;QAGH;;;;WAIG;;sBAqFM,MAAM,4BAEJ,MAAM;QAjFnB;;WAEG;;QAKH;;WAEG;;QAMH;;;;;;;;;WASG;wBAHQ,MAAM,0BAEJ,MAAM;QAkDnB;;;;;;;;;WASG;wBAHQ,MAAM,0BAEJ,MAAM;QAgDnB;;;;;WAKG;;QAOH;;;;WAIG;oBAFQ,MAAM,GACJ,MAAM;QAMnB;;;;;;;WAOG;qBAHQ,MAAM,0BAEJ,UAAU;QAmDvB;;;WAGG;qBAFQ,MAAM,GACJ,UAAU;;EAQtB"} \ No newline at end of file diff --git a/types/io/bytebuffer.d.ts b/types/io/bytebuffer.d.ts new file mode 100644 index 0000000..d815dd0 --- /dev/null +++ b/types/io/bytebuffer.d.ts @@ -0,0 +1,41 @@ +export const ByteBuffer: { + new (numBytes: number): { + /** + * @type {Uint8Array} + * @public + */ + data: Uint8Array; + /** + * @type {number} + * @public + */ + ptr: number; + /** + * @param {number} b The byte to insert. + */ + insertByte(b: number): void; + /** + * @param {Array.|Uint8Array|Int8Array} bytes The bytes to insert. + */ + insertBytes(bytes: Array | Uint8Array | Int8Array): void; + /** + * Writes an unsigned number into the next n bytes. If the number is too large + * to fit into n bytes or is negative, an error is thrown. + * @param {number} num The unsigned number to write. + * @param {number} numBytes The number of bytes to write the number into. + */ + writeNumber(num: number, numBytes: number): void; + /** + * Writes a signed number into the next n bytes. If the number is too large + * to fit into n bytes, an error is thrown. + * @param {number} num The signed number to write. + * @param {number} numBytes The number of bytes to write the number into. + */ + writeSignedNumber(num: number, numBytes: number): void; + /** + * @param {string} str The ASCII string to write. + */ + writeASCIIString(str: string): void; + }; +}; +//# sourceMappingURL=bytebuffer.d.ts.map \ No newline at end of file diff --git a/types/io/bytebuffer.d.ts.map b/types/io/bytebuffer.d.ts.map new file mode 100644 index 0000000..c6efdaa --- /dev/null +++ b/types/io/bytebuffer.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bytebuffer.d.ts","sourceRoot":"","sources":["../../io/bytebuffer.js"],"names":[],"mappings":"AACA;mBAkBe,MAAM;QAOf;;;WAGG;cAFO,UAAU;QAKpB;;;WAGG;aAFO,MAAM;QAOlB;;WAEG;sBADQ,MAAM;QAOjB;;WAEG;2BADQ,MAAO,MAAM,CAAC,GAAC,UAAU,GAAC,SAAS;QAQ9C;;;;;WAKG;yBAFQ,MAAM,YACN,MAAM;QAyBjB;;;;;WAKG;+BAFQ,MAAM,YACN,MAAM;QAuBjB;;WAEG;8BADQ,MAAM;;EAchB"} \ No newline at end of file diff --git a/types/io/bytestream.d.ts b/types/io/bytestream.d.ts new file mode 100644 index 0000000..64fb5d8 --- /dev/null +++ b/types/io/bytestream.d.ts @@ -0,0 +1,109 @@ +export const ByteStream: { + new (ab: ArrayBuffer, opt_offset?: number | undefined, opt_length?: number | undefined): { + /** + * The current page of bytes in the stream. + * @type {Uint8Array} + * @private + */ + bytes: Uint8Array; + /** + * The next pages of bytes in the stream. + * @type {Array} + * @private + */ + pages_: Array; + /** + * The byte in the current page that we will read next. + * @type {Number} + * @private + */ + ptr: number; + /** + * An ever-increasing number. + * @type {Number} + * @private + */ + bytesRead_: number; + /** + * Returns how many bytes have been read in the stream since the beginning of time. + */ + getNumBytesRead(): number; + /** + * Returns how many bytes are currently in the stream left to be read. + */ + getNumBytesLeft(): number; + /** + * Move the pointer ahead n bytes. If the pointer is at the end of the current array + * of bytes and we have another page of bytes, point at the new page. This is a private + * method, no validation is done. + * @param {number} n Number of bytes to increment. + * @private + */ + movePointer_(n: number): void; + /** + * Peeks at the next n bytes as an unsigned number but does not advance the + * pointer. + * @param {number} n The number of bytes to peek at. Must be a positive integer. + * @returns {number} The n bytes interpreted as an unsigned number. + */ + peekNumber(n: number): number; + /** + * Returns the next n bytes as an unsigned number (or -1 on error) + * and advances the stream pointer n bytes. + * @param {number} n The number of bytes to read. Must be a positive integer. + * @returns {number} The n bytes interpreted as an unsigned number. + */ + readNumber(n: number): number; + /** + * Returns the next n bytes as a signed number but does not advance the + * pointer. + * @param {number} n The number of bytes to read. Must be a positive integer. + * @returns {number} The bytes interpreted as a signed number. + */ + peekSignedNumber(n: number): number; + /** + * Returns the next n bytes as a signed number and advances the stream pointer. + * @param {number} n The number of bytes to read. Must be a positive integer. + * @returns {number} The bytes interpreted as a signed number. + */ + readSignedNumber(n: number): number; + /** + * This returns n bytes as a sub-array, advancing the pointer if movePointers + * is true. + * @param {number} n The number of bytes to read. Must be a positive integer. + * @param {boolean} movePointers Whether to move the pointers. + * @returns {Uint8Array} The subarray. + */ + peekBytes(n: number, movePointers: boolean): Uint8Array; + /** + * Reads the next n bytes as a sub-array. + * @param {number} n The number of bytes to read. Must be a positive integer. + * @returns {Uint8Array} The subarray. + */ + readBytes(n: number): Uint8Array; + /** + * Peeks at the next n bytes as an ASCII string but does not advance the pointer. + * @param {number} n The number of bytes to peek at. Must be a positive integer. + * @returns {string} The next n bytes as a string. + */ + peekString(n: number): string; + /** + * Returns the next n bytes as an ASCII string and advances the stream pointer + * n bytes. + * @param {number} n The number of bytes to read. Must be a positive integer. + * @returns {string} The next n bytes as a string. + */ + readString(n: number): string; + /** + * Feeds more bytes into the back of the stream. + * @param {ArrayBuffer} ab + */ + push(ab: ArrayBuffer): void; + /** + * Creates a new ByteStream from this ByteStream that can be read / peeked. + * @returns {ByteStream} A clone of this ByteStream. + */ + tee(): any; + }; +}; +//# sourceMappingURL=bytestream.d.ts.map \ No newline at end of file diff --git a/types/io/bytestream.d.ts.map b/types/io/bytestream.d.ts.map new file mode 100644 index 0000000..b9b05f5 --- /dev/null +++ b/types/io/bytestream.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"bytestream.d.ts","sourceRoot":"","sources":["../../io/bytestream.js"],"names":[],"mappings":"AACA;aAoBe,WAAW,eACX,MAAM,2BACN,MAAM;QAUf;;;;WAIG;eAFO,UAAU;QAKpB;;;;WAIG;gBAFO,MAAM,UAAU,CAAC;QAK3B;;;;WAIG;;QAGH;;;;WAIG;;QAIL;;WAEG;;QAKH;;WAEG;;QAMH;;;;;;WAMG;wBAFQ,MAAM;QAYjB;;;;;WAKG;sBAFQ,MAAM,GACJ,MAAM;QAqCnB;;;;;WAKG;sBAFQ,MAAM,GACJ,MAAM;QASnB;;;;;WAKG;4BAFQ,MAAM,GACJ,MAAM;QAanB;;;;WAIG;4BAFQ,MAAM,GACJ,MAAM;QASnB;;;;;;WAMG;qBAHQ,MAAM,gBACN,OAAO,GACL,UAAU;QA2CvB;;;;WAIG;qBAFQ,MAAM,GACJ,UAAU;QAMvB;;;;WAIG;sBAFQ,MAAM,GACJ,MAAM;QA+BnB;;;;;WAKG;sBAFQ,MAAM,GACJ,MAAM;QAQnB;;;WAGG;iBADQ,WAAW;QAatB;;;WAGG;;;EAYF"} \ No newline at end of file