mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-23 19:49:50 +02:00
feat: modernized
This commit is contained in:
1 parent
4bfe34ba53
commit
aa78bc4045
1 file changed
+12
-8
@@ -9,13 +9,13 @@ import { decodeBlock } from 'lz4';
|
|||||||
*/
|
*/
|
||||||
export async function readDVPL(file: string) {
|
export async function readDVPL(file: string) {
|
||||||
const buffer = await readFile(file);
|
const buffer = await readFile(file);
|
||||||
const footerBuffer = buffer.slice(buffer.length - 20, buffer.length);
|
const footerBuffer = buffer.subarray(buffer.length - 20, buffer.length);
|
||||||
|
|
||||||
if (
|
if (
|
||||||
footerBuffer.toString('utf8', 16, 20) !== 'DVPL' ||
|
footerBuffer.toString('utf8', 16, 20) !== 'DVPL' ||
|
||||||
footerBuffer.length !== 20
|
footerBuffer.length !== 20
|
||||||
) {
|
) {
|
||||||
throw 'InvalidDVPLFooter';
|
throw new SyntaxError('Invalid DVPL footer');
|
||||||
}
|
}
|
||||||
|
|
||||||
const footerData = {
|
const footerData = {
|
||||||
@@ -24,13 +24,17 @@ export async function readDVPL(file: string) {
|
|||||||
crc32: footerBuffer.readUInt32LE(8),
|
crc32: footerBuffer.readUInt32LE(8),
|
||||||
type: footerBuffer.readUInt32LE(12),
|
type: footerBuffer.readUInt32LE(12),
|
||||||
};
|
};
|
||||||
const targetBlock = buffer.slice(0, buffer.length - 20);
|
const targetBlock = buffer.subarray(0, buffer.length - 20);
|
||||||
|
|
||||||
if (targetBlock.length !== footerData.cSize) throw 'DVPLSizeMismatch';
|
if (targetBlock.length !== footerData.cSize) {
|
||||||
if (crc32(targetBlock) !== footerData.crc32) throw 'DVPLCRC32Mismatch';
|
throw new RangeError('DVPL size mismatch');
|
||||||
|
}
|
||||||
|
if (crc32(targetBlock) !== footerData.crc32) {
|
||||||
|
throw new TypeError('DVPL CRC32 mismatch');
|
||||||
|
}
|
||||||
if (footerData.type === 0) {
|
if (footerData.type === 0) {
|
||||||
if (!(footerData.oSize === footerData.cSize && footerData.type === 0)) {
|
if (!(footerData.oSize === footerData.cSize && footerData.type === 0)) {
|
||||||
throw 'DVPLTypeSizeMismatch';
|
throw new RangeError('DVPL type and size mismatch');
|
||||||
}
|
}
|
||||||
|
|
||||||
return targetBlock;
|
return targetBlock;
|
||||||
@@ -39,11 +43,11 @@ export async function readDVPL(file: string) {
|
|||||||
const DecompressedBlockSize = decodeBlock(targetBlock, deDVPLBlock);
|
const DecompressedBlockSize = decodeBlock(targetBlock, deDVPLBlock);
|
||||||
|
|
||||||
if (DecompressedBlockSize !== footerData.oSize) {
|
if (DecompressedBlockSize !== footerData.oSize) {
|
||||||
throw 'DVPLDecodeSizeMismatch';
|
throw new RangeError('Decompressed DVPL size mismatch');
|
||||||
}
|
}
|
||||||
|
|
||||||
return deDVPLBlock;
|
return deDVPLBlock;
|
||||||
} else {
|
} else {
|
||||||
throw new TypeError('Unknown DVPL format');
|
throw new SyntaxError('Unknown DVPL format');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user