Skip to content

Commit 14f82a8

Browse files
committed
Update TS types
1 parent 440478c commit 14f82a8

File tree

9 files changed

+49
-28
lines changed

9 files changed

+49
-28
lines changed

tests/archive-compress.spec.js

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,19 +22,17 @@ describe('bitjs.archive.compress', () => {
2222
let inputFileInfos = new Map();
2323
let decompressedFileSize = 0;
2424

25-
before(() => {
26-
for (const fileName of INPUT_FILENAMES) {
27-
const fullFilename = `${PATH}${fileName}`;
28-
const fd = fs.openSync(fullFilename, 'r');
29-
const lastModTime = fs.fstatSync(fd).mtimeMs;
30-
const nodeBuf = fs.readFileSync(fullFilename);
31-
const fileData = new Uint8Array(
32-
nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length));
33-
inputFileInfos.set(fileName, {fileName, lastModTime, fileData});
34-
decompressedFileSize += fileData.byteLength;
35-
fs.closeSync(fd);
36-
}
37-
});
25+
for (const fileName of INPUT_FILENAMES) {
26+
const fullFilename = `${PATH}${fileName}`;
27+
const fd = fs.openSync(fullFilename, 'r');
28+
const lastModTime = fs.fstatSync(fd).mtimeMs;
29+
const nodeBuf = fs.readFileSync(fullFilename);
30+
const fileData = new Uint8Array(
31+
nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length));
32+
inputFileInfos.set(fileName, {fileName, lastModTime, fileData});
33+
decompressedFileSize += fileData.byteLength;
34+
fs.closeSync(fd);
35+
}
3836

3937
it('zipper throws for invalid compression method', async () => {
4038
expect(() => new Zipper({zipCompressionMethod: 42})).throws();

tests/archive-decompress.spec.js

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,11 @@ describe('bitjs.archive.decompress', () => {
2929
/** @type {Map<string, ArrayBuffer>} */
3030
let inputArrayBuffers = new Map();
3131

32-
before(() => {
33-
for (const inputFile of INPUT_FILES) {
34-
const nodeBuf = fs.readFileSync(`${PATH}${inputFile}`);
35-
const ab = nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length);
36-
inputArrayBuffers.set(inputFile, ab);
37-
}
38-
});
32+
for (const inputFile of INPUT_FILES) {
33+
const nodeBuf = fs.readFileSync(`${PATH}${inputFile}`);
34+
const ab = nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length);
35+
inputArrayBuffers.set(inputFile, ab);
36+
}
3937

4038
for (const outFile of ARCHIVE_FILES) {
4139
it(outFile, async () => {
@@ -71,7 +69,7 @@ describe('bitjs.archive.decompress', () => {
7169
}
7270

7371
describe('gunzip', () => {
74-
it('can unzip a file', async () => {
72+
it('can gunzip a file', async () => {
7573
const bufs = new Map(inputArrayBuffers);
7674
const nodeBuf = fs.readFileSync(`${PATH}sample-1-slowest.txt.gz`);
7775
const ab = nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length);

types/archive/decompress.d.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,25 @@ export class Untarrer extends Unarchiver {
155155
*/
156156
constructor(ab: ArrayBuffer, options?: UnarchiverOptions);
157157
}
158+
/**
159+
* IMPORTANT NOTES for Gunzipper:
160+
* 1) A Gunzipper will only ever emit one EXTRACT event, because a gzipped file only ever contains
161+
* a single file.
162+
* 2) If the gzipped file does not include the original filename as a FNAME block, then the
163+
* UnarchivedFile in the UnarchiveExtractEvent will not include a filename. It will be up to the
164+
* client to re-assemble the filename (if needed).
165+
* 3) update() is not supported on a Gunzipper, since the current implementation relies on runtime
166+
* support for DecompressionStream('gzip') which can throw hard-to-detect errors reading only
167+
* only part of a file.
168+
* 4) PROGRESS events are not yet supported in Gunzipper.
169+
*/
170+
export class Gunzipper extends Unarchiver {
171+
/**
172+
* @param {ArrayBuffer} ab
173+
* @param {UnarchiverOptions} options
174+
*/
175+
constructor(ab: ArrayBuffer, options?: UnarchiverOptions);
176+
}
158177
export type UnarchivedFile = {
159178
filename: string;
160179
fileData: Uint8Array;

types/archive/decompress.d.ts.map

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

types/io/bitstream.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
*
77
* Bit reading always proceeds from the first byte in the buffer, to the
88
* second byte, and so on. The MTL flag controls which bit is considered
9-
* first *inside* the byte.
9+
* first *inside* the byte. The default is least-to-most direction.
1010
*
1111
* An Example for how Most-To-Least vs Least-to-Most mode works:
1212
*

types/io/bytebuffer.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ export class ByteBuffer {
1212
*/
1313
public data: Uint8Array;
1414
/**
15+
* Points to the byte that will next be written.
1516
* @type {number}
1617
* @public
1718
*/
1819
public ptr: number;
20+
/**
21+
* Returns an exact copy of all the data that has been written to the ByteBuffer.
22+
* @returns {Uint8Array}
23+
*/
24+
getData(): Uint8Array;
1925
/**
2026
* @param {number} b The byte to insert.
2127
*/

types/io/bytebuffer.d.ts.map

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

types/io/bytestream.d.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,15 +42,15 @@ export class ByteStream {
4242
* @private
4343
*/
4444
private littleEndian_;
45-
/** @returns {boolean} Whether the stream is little-endian. */
45+
/** @returns {boolean} Whether the stream is little-endian (least significant byte is first). */
4646
isLittleEndian(): boolean;
4747
/**
48-
* Big-Endian is sometimes called Motorola-style.
48+
* Big-Endian means the most significant byte is first. it is sometimes called Motorola-style.
4949
* @param {boolean=} val The value to set. If not present, the stream is set to big-endian.
5050
*/
5151
setBigEndian(val?: boolean | undefined): void;
5252
/**
53-
* Little-Endian is sometimes called Intel-style.
53+
* Little-Endian means the least significant byte is ifrst. is sometimes called Intel-style.
5454
* @param {boolean=} val The value to set. If not present, the stream is set to little-endian.
5555
*/
5656
setLittleEndian(val?: boolean | undefined): void;

types/io/bytestream.d.ts.map

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

0 commit comments

Comments
 (0)