Skip to content

Commit

Permalink
Update TS types
Browse files Browse the repository at this point in the history
  • Loading branch information
codedread committed Feb 5, 2024
1 parent 440478c commit 14f82a8
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 28 deletions.
24 changes: 11 additions & 13 deletions tests/archive-compress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,17 @@ describe('bitjs.archive.compress', () => {
let inputFileInfos = new Map();
let decompressedFileSize = 0;

before(() => {
for (const fileName of INPUT_FILENAMES) {
const fullFilename = `${PATH}${fileName}`;
const fd = fs.openSync(fullFilename, 'r');
const lastModTime = fs.fstatSync(fd).mtimeMs;
const nodeBuf = fs.readFileSync(fullFilename);
const fileData = new Uint8Array(
nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length));
inputFileInfos.set(fileName, {fileName, lastModTime, fileData});
decompressedFileSize += fileData.byteLength;
fs.closeSync(fd);
}
});
for (const fileName of INPUT_FILENAMES) {
const fullFilename = `${PATH}${fileName}`;
const fd = fs.openSync(fullFilename, 'r');
const lastModTime = fs.fstatSync(fd).mtimeMs;
const nodeBuf = fs.readFileSync(fullFilename);
const fileData = new Uint8Array(
nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length));
inputFileInfos.set(fileName, {fileName, lastModTime, fileData});
decompressedFileSize += fileData.byteLength;
fs.closeSync(fd);
}

it('zipper throws for invalid compression method', async () => {
expect(() => new Zipper({zipCompressionMethod: 42})).throws();
Expand Down
14 changes: 6 additions & 8 deletions tests/archive-decompress.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,11 @@ describe('bitjs.archive.decompress', () => {
/** @type {Map<string, ArrayBuffer>} */
let inputArrayBuffers = new Map();

before(() => {
for (const inputFile of INPUT_FILES) {
const nodeBuf = fs.readFileSync(`${PATH}${inputFile}`);
const ab = nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length);
inputArrayBuffers.set(inputFile, ab);
}
});
for (const inputFile of INPUT_FILES) {
const nodeBuf = fs.readFileSync(`${PATH}${inputFile}`);
const ab = nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length);
inputArrayBuffers.set(inputFile, ab);
}

for (const outFile of ARCHIVE_FILES) {
it(outFile, async () => {
Expand Down Expand Up @@ -71,7 +69,7 @@ describe('bitjs.archive.decompress', () => {
}

describe('gunzip', () => {
it('can unzip a file', async () => {
it('can gunzip a file', async () => {
const bufs = new Map(inputArrayBuffers);
const nodeBuf = fs.readFileSync(`${PATH}sample-1-slowest.txt.gz`);
const ab = nodeBuf.buffer.slice(nodeBuf.byteOffset, nodeBuf.byteOffset + nodeBuf.length);
Expand Down
19 changes: 19 additions & 0 deletions types/archive/decompress.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,25 @@ export class Untarrer extends Unarchiver {
*/
constructor(ab: ArrayBuffer, options?: UnarchiverOptions);
}
/**
* IMPORTANT NOTES for Gunzipper:
* 1) A Gunzipper will only ever emit one EXTRACT event, because a gzipped file only ever contains
* a single file.
* 2) If the gzipped file does not include the original filename as a FNAME block, then the
* UnarchivedFile in the UnarchiveExtractEvent will not include a filename. It will be up to the
* client to re-assemble the filename (if needed).
* 3) update() is not supported on a Gunzipper, since the current implementation relies on runtime
* support for DecompressionStream('gzip') which can throw hard-to-detect errors reading only
* only part of a file.
* 4) PROGRESS events are not yet supported in Gunzipper.
*/
export class Gunzipper extends Unarchiver {
/**
* @param {ArrayBuffer} ab
* @param {UnarchiverOptions} options
*/
constructor(ab: ArrayBuffer, options?: UnarchiverOptions);
}
export type UnarchivedFile = {
filename: string;
fileData: Uint8Array;
Expand Down
2 changes: 1 addition & 1 deletion types/archive/decompress.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion types/io/bitstream.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*
* Bit reading always proceeds from the first byte in the buffer, to the
* second byte, and so on. The MTL flag controls which bit is considered
* first *inside* the byte.
* first *inside* the byte. The default is least-to-most direction.
*
* An Example for how Most-To-Least vs Least-to-Most mode works:
*
Expand Down
6 changes: 6 additions & 0 deletions types/io/bytebuffer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,16 @@ export class ByteBuffer {
*/
public data: Uint8Array;
/**
* Points to the byte that will next be written.
* @type {number}
* @public
*/
public ptr: number;
/**
* Returns an exact copy of all the data that has been written to the ByteBuffer.
* @returns {Uint8Array}
*/
getData(): Uint8Array;
/**
* @param {number} b The byte to insert.
*/
Expand Down
2 changes: 1 addition & 1 deletion types/io/bytebuffer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions types/io/bytestream.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ export class ByteStream {
* @private
*/
private littleEndian_;
/** @returns {boolean} Whether the stream is little-endian. */
/** @returns {boolean} Whether the stream is little-endian (least significant byte is first). */
isLittleEndian(): boolean;
/**
* Big-Endian is sometimes called Motorola-style.
* Big-Endian means the most significant byte is first. it is sometimes called Motorola-style.
* @param {boolean=} val The value to set. If not present, the stream is set to big-endian.
*/
setBigEndian(val?: boolean | undefined): void;
/**
* Little-Endian is sometimes called Intel-style.
* Little-Endian means the least significant byte is ifrst. is sometimes called Intel-style.
* @param {boolean=} val The value to set. If not present, the stream is set to little-endian.
*/
setLittleEndian(val?: boolean | undefined): void;
Expand Down
2 changes: 1 addition & 1 deletion types/io/bytestream.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 14f82a8

Please sign in to comment.