From 14f82a83bc65d3ae808e1d20a4a05fb62ef6e86f Mon Sep 17 00:00:00 2001 From: Jeff Schiller Date: Sun, 4 Feb 2024 21:22:21 -0800 Subject: [PATCH] Update TS types --- tests/archive-compress.spec.js | 24 +++++++++++------------- tests/archive-decompress.spec.js | 14 ++++++-------- types/archive/decompress.d.ts | 19 +++++++++++++++++++ types/archive/decompress.d.ts.map | 2 +- types/io/bitstream.d.ts | 2 +- types/io/bytebuffer.d.ts | 6 ++++++ types/io/bytebuffer.d.ts.map | 2 +- types/io/bytestream.d.ts | 6 +++--- types/io/bytestream.d.ts.map | 2 +- 9 files changed, 49 insertions(+), 28 deletions(-) diff --git a/tests/archive-compress.spec.js b/tests/archive-compress.spec.js index 36afb34..b5b0654 100644 --- a/tests/archive-compress.spec.js +++ b/tests/archive-compress.spec.js @@ -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(); diff --git a/tests/archive-decompress.spec.js b/tests/archive-decompress.spec.js index c0c38d5..f09045b 100644 --- a/tests/archive-decompress.spec.js +++ b/tests/archive-decompress.spec.js @@ -29,13 +29,11 @@ describe('bitjs.archive.decompress', () => { /** @type {Map} */ 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 () => { @@ -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); diff --git a/types/archive/decompress.d.ts b/types/archive/decompress.d.ts index ebaa1c9..4059430 100644 --- a/types/archive/decompress.d.ts +++ b/types/archive/decompress.d.ts @@ -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; diff --git a/types/archive/decompress.d.ts.map b/types/archive/decompress.d.ts.map index ada8dff..6c2c8a8 100644 --- a/types/archive/decompress.d.ts.map +++ b/types/archive/decompress.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../../archive/decompress.js"],"names":[],"mappings":"AAmUA;;;;;;;;;;GAUG;AACH,kCARW,WAAW,YAGX,iBAAiB,GAAC,MAAM,GAGtB,UAAU,CAkBtB;AAhUD;;;;GAIG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;GAEG;AACH;IAgBE;;;;;;;OAOG;IACH,yBAPW,WAAW,YAGX,iBAAiB,GAAC,MAAM,EA0BlC;IA7CD;;;;;OAKG;IACH,cAAM;IAEN;;;;OAIG;IACH,sBAAc;IAoBZ;;;;OAIG;IACH,cAHU,WAAW,CAGA;IAErB;;;OAGG;IACH,YAFU,OAAO,CAEkB;IAGrC;;;;;OAKG;IACH,qCAJW,UAAU,GAAC,SAAS,GAAC,QAAQ,YAC7B,kCAAkC,QAK5C;IAED;;;;OAIG;IACH,2BAHoB,qBAAqB,WAC5B,UAAU,CAKtB;IAED;;;;OAIG;IACH,0BAHoB,oBAAoB,WAC3B,UAAU,CAKtB;IAED;;;;OAIG;IACH,4BAHoB,sBAAsB,WAC7B,UAAU,CAKtB;IAED;;;;OAIG;IACH,yBAHa,MAAM,CAKlB;IAED;;;;OAIG;IACH,+BAHa,MAAM,CAKlB;IAED;;;;;OAKG;IACH,8BAsBC;IAED;;;;;OAKG;IACH,yBAaC;IAED;;;;;OAKG;IACH,SAJa,QAAQ,IAAI,CAAC,CAgCzB;IAGD;;;;;;;;OAQG;IACH,WAPW,WAAW,qBAGX,OAAO,oBAgBjB;IAED;;OAEG;IACH,aAOC;CACF;AAID;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;AAED;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;AAED;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;;cAzRa,MAAM;cACN,UAAU;;;;;;YAKV,OAAO"} \ No newline at end of file +{"version":3,"file":"decompress.d.ts","sourceRoot":"","sources":["../../archive/decompress.js"],"names":[],"mappings":"AA4VA;;;;;;;;;;GAUG;AACH,kCARW,WAAW,YAGX,iBAAiB,GAAC,MAAM,GAGtB,UAAU,CAoBtB;AA3VD;;;;GAIG;AAEH;;;;GAIG;AAEH;;;GAGG;AAEH;;GAEG;AACH;IAgBE;;;;;;;OAOG;IACH,yBAPW,WAAW,YAGX,iBAAiB,GAAC,MAAM,EA0BlC;IA7CD;;;;;OAKG;IACH,cAAM;IAEN;;;;OAIG;IACH,sBAAc;IAoBZ;;;;OAIG;IACH,cAHU,WAAW,CAGA;IAErB;;;OAGG;IACH,YAFU,OAAO,CAEkB;IAGrC;;;;;OAKG;IACH,qCAJW,UAAU,GAAC,SAAS,GAAC,QAAQ,YAC7B,kCAAkC,QAK5C;IAED;;;;OAIG;IACH,2BAHoB,qBAAqB,WAC5B,UAAU,CAKtB;IAED;;;;OAIG;IACH,0BAHoB,oBAAoB,WAC3B,UAAU,CAKtB;IAED;;;;OAIG;IACH,4BAHoB,sBAAsB,WAC7B,UAAU,CAKtB;IAED;;;;OAIG;IACH,yBAHa,MAAM,CAKlB;IAED;;;;OAIG;IACH,+BAHa,MAAM,CAKlB;IAED;;;;;OAKG;IACH,8BAsBC;IAED;;;;;OAKG;IACH,yBAaC;IAED;;;;;OAKG;IACH,SAJa,QAAQ,IAAI,CAAC,CAgCzB;IAGD;;;;;;;;OAQG;IACH,WAPW,WAAW,qBAGX,OAAO,oBAgBjB;IAED;;OAEG;IACH,aAOC;CACF;AAID;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;AAED;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;AAED;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;AAED;;;;;;;;;;;GAWG;AACH;IACE;;;OAGG;IACH,gBAHW,WAAW,YACX,iBAAiB,EAI3B;CAIF;;cAlTa,MAAM;cACN,UAAU;;;;;;YAKV,OAAO"} \ No newline at end of file diff --git a/types/io/bitstream.d.ts b/types/io/bitstream.d.ts index 7e77a0f..450228d 100644 --- a/types/io/bitstream.d.ts +++ b/types/io/bitstream.d.ts @@ -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: * diff --git a/types/io/bytebuffer.d.ts b/types/io/bytebuffer.d.ts index 6f8d580..c2952be 100644 --- a/types/io/bytebuffer.d.ts +++ b/types/io/bytebuffer.d.ts @@ -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. */ diff --git a/types/io/bytebuffer.d.ts.map b/types/io/bytebuffer.d.ts.map index f9f7ef1..811c7fb 100644 --- a/types/io/bytebuffer.d.ts.map +++ b/types/io/bytebuffer.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"bytebuffer.d.ts","sourceRoot":"","sources":["../../io/bytebuffer.js"],"names":[],"mappings":"AAaA;;GAEG;AACH;IACE;;OAEG;IACH,sBAFW,MAAM,EAkBhB;IAXC;;;OAGG;IACH,aAHU,UAAU,CAGgB;IAEpC;;;OAGG;IACH,YAHU,MAAM,CAGJ;IAId;;OAEG;IACH,cAFW,MAAM,QAKhB;IAED;;OAEG;IACH,mBAFW,MAAO,MAAM,CAAC,GAAC,UAAU,GAAC,SAAS,QAM7C;IAED;;;;;OAKG;IACH,iBAHW,MAAM,YACN,MAAM,QAuBhB;IAED;;;;;OAKG;IACH,uBAHW,MAAM,YACN,MAAM,QAqBhB;IAED;;OAEG;IACH,sBAFW,MAAM,QAUhB;CACF"} \ No newline at end of file +{"version":3,"file":"bytebuffer.d.ts","sourceRoot":"","sources":["../../io/bytebuffer.js"],"names":[],"mappings":"AAaA;;GAEG;AACH;IACE;;OAEG;IACH,sBAFW,MAAM,EAmBhB;IAZC;;;OAGG;IACH,aAHU,UAAU,CAGgB;IAEpC;;;;OAIG;IACH,YAHU,MAAM,CAGJ;IAGd;;;OAGG;IACH,WAFa,UAAU,CAMtB;IAED;;OAEG;IACH,cAFW,MAAM,QAShB;IAED;;OAEG;IACH,mBAFW,MAAO,MAAM,CAAC,GAAC,UAAU,GAAC,SAAS,QAU7C;IAED;;;;;OAKG;IACH,iBAHW,MAAM,YACN,MAAM,QAuBhB;IAED;;;;;OAKG;IACH,uBAHW,MAAM,YACN,MAAM,QAqBhB;IAED;;OAEG;IACH,sBAFW,MAAM,QAUhB;CACF"} \ No newline at end of file diff --git a/types/io/bytestream.d.ts b/types/io/bytestream.d.ts index 188083b..cfcf1f2 100644 --- a/types/io/bytestream.d.ts +++ b/types/io/bytestream.d.ts @@ -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; diff --git a/types/io/bytestream.d.ts.map b/types/io/bytestream.d.ts.map index 3b4498f..509176c 100644 --- a/types/io/bytestream.d.ts.map +++ b/types/io/bytestream.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"bytestream.d.ts","sourceRoot":"","sources":["../../io/bytestream.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH;IACE;;;;OAIG;IACH,gBAJW,WAAW,eACX,MAAM,2BACN,MAAM,cA4ChB;IAlCC;;;;OAIG;IACH,cAA+C;IAE/C;;;;OAIG;IACH,eAAgB;IAEhB;;;;OAIG;IACH,YAAY;IAEZ;;;;OAIG;IACH,mBAAmB;IAEnB;;;;OAIG;IACH,sBAAyB;IAG3B,8DAA8D;IAC9D,kBADc,OAAO,CAGpB;IAED;;;OAGG;IACH,mBAFW,OAAO,oBAIjB;IAED;;;OAGG;IACH,sBAFW,OAAO,oBAIjB;IAED;;;OAGG;IACH,mBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,mBAFa,MAAM,CAKlB;IAED;;;;;;OAMG;IACH,qBAOC;IAED;;;;;OAKG;IACH,cAHW,MAAM,GACJ,MAAM,CAmClB;IAGD;;;;;OAKG;IACH,cAHW,MAAM,GACJ,MAAM,CAMlB;IAGD;;;;;OAKG;IACH,oBAHW,MAAM,GACJ,MAAM,CAUlB;IAGD;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAMlB;IAGD;;;;;;OAMG;IACH,aAJW,MAAM,gBACN,OAAO,GACL,UAAU,CAyCtB;IAED;;;;OAIG;IACH,aAHW,MAAM,GACJ,UAAU,CAItB;IAED;;;;OAIG;IACH,cAHW,MAAM,GACJ,MAAM,CA6BlB;IAED;;;;;OAKG;IACH,cAHW,MAAM,GACJ,MAAM,CAMlB;IAED;;;;OAIG;IACH,QAHW,MAAM,GACJ,UAAU,CAkBtB;IAED;;;OAGG;IACH,SAFW,WAAW,QAWrB;IAED;;;;;;;OAOG;IACH,OAFa,UAAU,CAUtB;CACF"} \ No newline at end of file +{"version":3,"file":"bytestream.d.ts","sourceRoot":"","sources":["../../io/bytestream.js"],"names":[],"mappings":"AAWA;;;;;;GAMG;AACH;IACE;;;;OAIG;IACH,gBAJW,WAAW,eACX,MAAM,2BACN,MAAM,cA4ChB;IAlCC;;;;OAIG;IACH,cAA+C;IAE/C;;;;OAIG;IACH,eAAgB;IAEhB;;;;OAIG;IACH,YAAY;IAEZ;;;;OAIG;IACH,mBAAmB;IAEnB;;;;OAIG;IACH,sBAAyB;IAG3B,gGAAgG;IAChG,kBADc,OAAO,CAGpB;IAED;;;OAGG;IACH,mBAFW,OAAO,oBAIjB;IAED;;;OAGG;IACH,sBAFW,OAAO,oBAIjB;IAED;;;OAGG;IACH,mBAFa,MAAM,CAIlB;IAED;;;OAGG;IACH,mBAFa,MAAM,CAKlB;IAED;;;;;;OAMG;IACH,qBAOC;IAED;;;;;OAKG;IACH,cAHW,MAAM,GACJ,MAAM,CAmClB;IAGD;;;;;OAKG;IACH,cAHW,MAAM,GACJ,MAAM,CAMlB;IAGD;;;;;OAKG;IACH,oBAHW,MAAM,GACJ,MAAM,CAUlB;IAGD;;;;OAIG;IACH,oBAHW,MAAM,GACJ,MAAM,CAMlB;IAGD;;;;;;OAMG;IACH,aAJW,MAAM,gBACN,OAAO,GACL,UAAU,CAyCtB;IAED;;;;OAIG;IACH,aAHW,MAAM,GACJ,UAAU,CAItB;IAED;;;;OAIG;IACH,cAHW,MAAM,GACJ,MAAM,CA6BlB;IAED;;;;;OAKG;IACH,cAHW,MAAM,GACJ,MAAM,CAMlB;IAED;;;;OAIG;IACH,QAHW,MAAM,GACJ,UAAU,CAkBtB;IAED;;;OAGG;IACH,SAFW,WAAW,QAWrB;IAED;;;;;;;OAOG;IACH,OAFa,UAAU,CAUtB;CACF"} \ No newline at end of file