Skip to content

Commit d5971c0

Browse files
committed
Correct some typos, expose codecs in the main module (woops), and provide Typescript types (d.ts files)
1 parent 28e8a8e commit d5971c0

23 files changed

+701
-5
lines changed

codecs/codecs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
*/
1313

1414
/**
15-
* @typdef ProbeStream ffprobe -show_streams -print_format json. Only the fields we care about.
15+
* @typedef ProbeStream ffprobe -show_streams -print_format json. Only the fields we care about.
1616
* @property {number} index
1717
* @property {string} codec_name
1818
* @property {string} codec_long_name

image/webp-shim/webp-shim.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function loadWebPShimApi() {
4747
}
4848

4949
/**
50-
* @param {ArrayBuffer|TypedArray} webpBuffer The byte array containing the WebP image bytes.
50+
* @param {ArrayBuffer|Uint8Array} webpBuffer The byte array containing the WebP image bytes.
5151
* @returns {Promise<ArrayBuffer>} A Promise resolving to a byte array containing the PNG bytes.
5252
*/
5353
export function convertWebPtoPNG(webpBuffer) {
@@ -76,7 +76,7 @@ export function convertWebPtoPNG(webpBuffer) {
7676
}
7777

7878
/**
79-
* @param {ArrayBuffer|TypedArray} webpBuffer The byte array containing the WebP image bytes.
79+
* @param {ArrayBuffer|Uint8Array} webpBuffer The byte array containing the WebP image bytes.
8080
* @returns {Promise<ArrayBuffer>} A Promise resolving to a byte array containing the JPG bytes.
8181
*/
8282
export function convertWebPtoJPG(webpBuffer) {

index.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,22 @@
66
* Copyright(c) 2020 Google Inc.
77
*/
88

9+
/**
10+
* @typedef {import('./codecs/codecs.js').ProbeStream} ProbeStream
11+
*/
12+
/**
13+
* @typedef {import('./codecs/codecs.js').ProbeFormat} ProbeFormat
14+
*/
15+
/**
16+
* @typedef {import('./codecs/codecs.js').ProbeInfo} ProbeInfo
17+
*/
18+
919
export {
1020
UnarchiveEvent, UnarchiveEventType, UnarchiveInfoEvent, UnarchiveErrorEvent,
1121
UnarchiveStartEvent, UnarchiveFinishEvent, UnarchiveProgressEvent, UnarchiveExtractEvent,
1222
Unarchiver, Unzipper, Unrarrer, Untarrer, getUnarchiver
1323
} from './archive/archive.js';
24+
export { getFullMIMEString, getShortMIMEString } from './codecs/codecs.js';
1425
export { findMimeType } from './file/sniffer.js';
1526
export { convertWebPtoPNG, convertWebPtoJPG } from './image/webp-shim/webp-shim.js';
1627
export { BitStream } from './io/bitstream.js';

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@codedread/bitjs",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"description": "Binary Tools for JavaScript",
55
"homepage": "https://github.com/codedread/bitjs",
66
"author": "Jeff Schiller",
@@ -24,6 +24,7 @@
2424
],
2525
"main": "./index.js",
2626
"type": "module",
27+
"types": "types/index.d.ts",
2728
"exports": "./index.js",
2829
"repository": {
2930
"type": "git",
@@ -42,7 +43,8 @@
4243
},
4344
"devDependencies": {
4445
"chai": "^4.3.4",
45-
"mocha": "^8.4.0"
46+
"mocha": "^8.4.0",
47+
"typescript": "^4.8.0"
4648
},
4749
"dependencies": {}
4850
}

tsconfig.json

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
// Change this to match your project
3+
"include": ["index.js"],
4+
"exclude": [],
5+
"compilerOptions": {
6+
// Tells TypeScript to read JS files, as
7+
// normally they are ignored as source files
8+
"allowJs": true,
9+
// Generate d.ts files
10+
"declaration": true,
11+
// This compiler run should
12+
// only output d.ts files
13+
"emitDeclarationOnly": true,
14+
// Types should go into this directory.
15+
// Removing this would place the .d.ts files
16+
// next to the .js files
17+
"outDir": "types",
18+
// go to js file when using IDE functions like
19+
// "Go to Definition" in VSCode
20+
"declarationMap": true
21+
}
22+
}

types/archive/archive.d.ts

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* Factory method that creates an unarchiver based on the byte signature found
3+
* in the arrayBuffer.
4+
* @param {ArrayBuffer} ab The ArrayBuffer to unarchive. Note that this ArrayBuffer
5+
* must not be referenced after calling this method, as the ArrayBuffer is marked
6+
* as Transferable and sent to a Worker thread once start() is called.
7+
* @param {Object|string} options An optional object of options, or a string
8+
* representing where the path to the unarchiver script files.
9+
* @returns {Unarchiver}
10+
*/
11+
export function getUnarchiver(ab: ArrayBuffer, options?: any | string): Unarchiver;
12+
export class Unzipper extends UnzipperInternal {
13+
constructor(ab: any, options: any);
14+
}
15+
export class Unrarrer extends UnrarrerInternal {
16+
constructor(ab: any, options: any);
17+
}
18+
export class Untarrer extends UntarrerInternal {
19+
constructor(ab: any, options: any);
20+
}
21+
export type UnarchivedFile = {
22+
filename: string;
23+
fileData: Uint8Array;
24+
};
25+
import { Unarchiver } from "./decompress-internal.js";
26+
import { UnarchiveAppendEvent } from "./decompress-internal.js";
27+
import { UnarchiveErrorEvent } from "./decompress-internal.js";
28+
import { UnarchiveEvent } from "./decompress-internal.js";
29+
import { UnarchiveEventType } from "./decompress-internal.js";
30+
import { UnarchiveExtractEvent } from "./decompress-internal.js";
31+
import { UnarchiveFinishEvent } from "./decompress-internal.js";
32+
import { UnarchiveInfoEvent } from "./decompress-internal.js";
33+
import { UnarchiveProgressEvent } from "./decompress-internal.js";
34+
import { UnarchiveStartEvent } from "./decompress-internal.js";
35+
import { UnzipperInternal } from "./decompress-internal.js";
36+
import { UnrarrerInternal } from "./decompress-internal.js";
37+
import { UntarrerInternal } from "./decompress-internal.js";
38+
export { UnarchiveAppendEvent, UnarchiveErrorEvent, UnarchiveEvent, UnarchiveEventType, UnarchiveExtractEvent, UnarchiveFinishEvent, UnarchiveInfoEvent, UnarchiveProgressEvent, UnarchiveStartEvent, Unarchiver };
39+
//# sourceMappingURL=archive.d.ts.map

types/archive/archive.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 245 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,245 @@
1+
/**
2+
* Factory method that creates an unarchiver based on the byte signature found
3+
* in the arrayBuffer.
4+
* @param {ArrayBuffer} ab
5+
* @param {Function(string):Worker} createWorkerFn A function that creates a Worker from a script file.
6+
* @param {Object|string} options An optional object of options, or a string representing where
7+
* the path to the unarchiver script files.
8+
* @returns {Unarchiver}
9+
*/
10+
export function getUnarchiverInternal(ab: ArrayBuffer, createWorkerFn: any, options?: any | string): Unarchiver;
11+
export namespace UnarchiveEventType {
12+
const START: string;
13+
const APPEND: string;
14+
const PROGRESS: string;
15+
const EXTRACT: string;
16+
const FINISH: string;
17+
const INFO: string;
18+
const ERROR: string;
19+
}
20+
/**
21+
* An unarchive event.
22+
*/
23+
export class UnarchiveEvent {
24+
/**
25+
* @param {string} type The event type.
26+
*/
27+
constructor(type: string);
28+
/**
29+
* The event type.
30+
* @type {string}
31+
*/
32+
type: string;
33+
}
34+
/**
35+
* Updates all Archiver listeners that an append has occurred.
36+
*/
37+
export class UnarchiveAppendEvent extends UnarchiveEvent {
38+
/**
39+
* @param {number} numBytes The number of bytes appended.
40+
*/
41+
constructor(numBytes: number);
42+
/**
43+
* The number of appended bytes.
44+
* @type {number}
45+
*/
46+
numBytes: number;
47+
}
48+
/**
49+
* Useful for passing info up to the client (for debugging).
50+
*/
51+
export class UnarchiveInfoEvent extends UnarchiveEvent {
52+
/**
53+
* The information message.
54+
* @type {string}
55+
*/
56+
msg: string;
57+
}
58+
/**
59+
* An unrecoverable error has occured.
60+
*/
61+
export class UnarchiveErrorEvent extends UnarchiveEvent {
62+
/**
63+
* The information message.
64+
* @type {string}
65+
*/
66+
msg: string;
67+
}
68+
/**
69+
* Start event.
70+
*/
71+
export class UnarchiveStartEvent extends UnarchiveEvent {
72+
constructor();
73+
}
74+
/**
75+
* Finish event.
76+
*/
77+
export class UnarchiveFinishEvent extends UnarchiveEvent {
78+
/**
79+
* @param {Object} metadata A collection fo metadata about the archive file.
80+
*/
81+
constructor(metadata?: any);
82+
metadata: any;
83+
}
84+
/**
85+
* Progress event.
86+
*/
87+
export class UnarchiveProgressEvent extends UnarchiveEvent {
88+
/**
89+
* @param {string} currentFilename
90+
* @param {number} currentFileNumber
91+
* @param {number} currentBytesUnarchivedInFile
92+
* @param {number} currentBytesUnarchived
93+
* @param {number} totalUncompressedBytesInArchive
94+
* @param {number} totalFilesInArchive
95+
* @param {number} totalCompressedBytesRead
96+
*/
97+
constructor(currentFilename: string, currentFileNumber: number, currentBytesUnarchivedInFile: number, currentBytesUnarchived: number, totalUncompressedBytesInArchive: number, totalFilesInArchive: number, totalCompressedBytesRead: number);
98+
currentFilename: string;
99+
currentFileNumber: number;
100+
currentBytesUnarchivedInFile: number;
101+
totalFilesInArchive: number;
102+
currentBytesUnarchived: number;
103+
totalUncompressedBytesInArchive: number;
104+
totalCompressedBytesRead: number;
105+
}
106+
/**
107+
* Extract event.
108+
*/
109+
export class UnarchiveExtractEvent extends UnarchiveEvent {
110+
/**
111+
* @param {UnarchivedFile} unarchivedFile
112+
*/
113+
constructor(unarchivedFile: UnarchivedFile);
114+
/**
115+
* @type {UnarchivedFile}
116+
*/
117+
unarchivedFile: UnarchivedFile;
118+
}
119+
/**
120+
* Base class for all Unarchivers.
121+
* TODO: When EventTarget constructors are broadly supported, make this extend
122+
* EventTarget and remove event listener code.
123+
* https://caniuse.com/#feat=mdn-api_eventtarget_eventtarget
124+
*/
125+
export class Unarchiver {
126+
/**
127+
* @param {ArrayBuffer} arrayBuffer The Array Buffer. Note that this ArrayBuffer must not be
128+
* referenced once it is sent to the Unarchiver, since it is marked as Transferable and sent
129+
* to the Worker.
130+
* @param {Function(string):Worker} createWorkerFn A function that creates a Worker from a script file.
131+
* @param {Object|string} options An optional object of options, or a string representing where
132+
* the BitJS files are located. The string version of this argument is deprecated.
133+
* Available options:
134+
* 'pathToBitJS': A string indicating where the BitJS files are located.
135+
* 'debug': A boolean where true indicates that the archivers should log debug output.
136+
*/
137+
constructor(arrayBuffer: ArrayBuffer, createWorkerFn: any, options?: any | string);
138+
/**
139+
* The ArrayBuffer object.
140+
* @type {ArrayBuffer}
141+
* @protected
142+
*/
143+
protected ab: ArrayBuffer;
144+
/**
145+
* A factory method that creates a Worker that does the unarchive work.
146+
* @type {Function(string): Worker}
147+
* @private
148+
*/
149+
private createWorkerFn_;
150+
/**
151+
* The path to the BitJS files.
152+
* @type {string}
153+
* @private
154+
*/
155+
private pathToBitJS_;
156+
/**
157+
* @orivate
158+
* @type {boolean}
159+
*/
160+
debugMode_: boolean;
161+
/**
162+
* A map from event type to an array of listeners.
163+
* @private
164+
* @type {Map.<string, Array>}
165+
*/
166+
private listeners_;
167+
/**
168+
* Private web worker initialized during start().
169+
* @private
170+
* @type {Worker}
171+
*/
172+
private worker_;
173+
/**
174+
* This method must be overridden by the subclass to return the script filename.
175+
* @returns {string} The MIME type of the archive.
176+
* @protected.
177+
*/
178+
protected getMIMEType(): string;
179+
/**
180+
* This method must be overridden by the subclass to return the script filename.
181+
* @returns {string} The script filename.
182+
* @protected.
183+
*/
184+
protected getScriptFileName(): string;
185+
/**
186+
* Adds an event listener for UnarchiveEvents.
187+
*
188+
* @param {string} Event type.
189+
* @param {function} An event handler function.
190+
*/
191+
addEventListener(type: any, listener: any): void;
192+
/**
193+
* Removes an event listener.
194+
*
195+
* @param {string} Event type.
196+
* @param {EventListener|function} An event listener or handler function.
197+
*/
198+
removeEventListener(type: any, listener: any): void;
199+
/**
200+
* Create an UnarchiveEvent out of the object sent back from the Worker.
201+
* @param {Object} obj
202+
* @returns {UnarchiveEvent}
203+
* @private
204+
*/
205+
private createUnarchiveEvent_;
206+
/**
207+
* Receive an event and pass it to the listener functions.
208+
*
209+
* @param {Object} obj
210+
* @private
211+
*/
212+
private handleWorkerEvent_;
213+
/**
214+
* Starts the unarchive in a separate Web Worker thread and returns immediately.
215+
*/
216+
start(): void;
217+
/**
218+
* Adds more bytes to the unarchiver's Worker thread.
219+
* @param {ArrayBuffer} ab The ArrayBuffer with more bytes in it. If opt_transferable is
220+
* set to true, this ArrayBuffer must not be referenced after calling update(), since it
221+
* is marked as Transferable and sent to the Worker.
222+
* @param {boolean=} opt_transferable Optional boolean whether to mark this ArrayBuffer
223+
* as a Tranferable object, which means it can no longer be referenced outside of
224+
* the Worker thread.
225+
*/
226+
update(ab: ArrayBuffer, opt_transferable?: boolean | undefined): void;
227+
/**
228+
* Terminates the Web Worker for this Unarchiver and returns immediately.
229+
*/
230+
stop(): void;
231+
}
232+
export class UnzipperInternal extends Unarchiver {
233+
constructor(arrayBuffer: any, createWorkerFn: any, options: any);
234+
}
235+
export class UnrarrerInternal extends Unarchiver {
236+
constructor(arrayBuffer: any, createWorkerFn: any, options: any);
237+
}
238+
export class UntarrerInternal extends Unarchiver {
239+
constructor(arrayBuffer: any, createWorkerFn: any, options: any);
240+
}
241+
export type UnarchivedFile = {
242+
filename: string;
243+
fileData: Uint8Array;
244+
};
245+
//# sourceMappingURL=decompress-internal.d.ts.map

types/archive/decompress-internal.d.ts.map

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)