Compatibility improvements and minor fixes

* Account for padding byte when chunk length is not a multiple of 2
* Use chunkLength to parse TINY and BODY chunk data
* Rename chunkID, lenChunk and formatID
* Deduplicate decompression code
This commit is contained in:
Michael Smith
2023-05-13 21:38:01 +02:00
parent d97a039cd8
commit 9dcbdd0327
2 changed files with 67 additions and 68 deletions

View File

@@ -37,22 +37,13 @@ test("Successfully parse a PBM file", () => {
}).not.toThrowError();
});
test("Fail to parse", () => {
const fs = require("fs");
const data = fs.readFileSync("./tests/fixtures/ASH.LBM");
expect(() => {
new PBM(data.buffer);
}).toThrowError(/^Failed to parse file.$/);
});
test("Fail to parse a PBM file with an invalid chunk id", () => {
const fs = require("fs");
const data = fs.readFileSync("./tests/fixtures/INVALID_CHUNK_ID.LBM");
expect(() => {
new PBM(data.buffer);
}).toThrowError(/^Invalid chunkID: "FARM" at byte 12. Expected "FORM".$/);
}).toThrowError(/^Invalid chunkId: "FARM" at byte 12. Expected "FORM".$/);
});
test("Fail to parse a PBM file with an invalid chunk length", () => {
@@ -70,7 +61,7 @@ test("Fail to parse an IFF file that is not a PBM file", () => {
expect(() => {
new PBM(data.buffer);
}).toThrowError(/^Invalid formatID: "ILBM". Expected "PBM ".$/);
}).toThrowError(/^Invalid formatId: "ILBM". Expected "PBM ".$/);
});
test("Parse a PBM bitmap header", () => {