mirror of
https://github.com/blitzkit/blitzkit.git
synced 2026-10-21 02:37:05 +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) {
|
||||
const buffer = await readFile(file);
|
||||
const footerBuffer = buffer.slice(buffer.length - 20, buffer.length);
|
||||
const footerBuffer = buffer.subarray(buffer.length - 20, buffer.length);
|
||||
|
||||
if (
|
||||
footerBuffer.toString('utf8', 16, 20) !== 'DVPL' ||
|
||||
footerBuffer.length !== 20
|
||||
) {
|
||||
throw 'InvalidDVPLFooter';
|
||||
throw new SyntaxError('Invalid DVPL footer');
|
||||
}
|
||||
|
||||
const footerData = {
|
||||
@@ -24,13 +24,17 @@ export async function readDVPL(file: string) {
|
||||
crc32: footerBuffer.readUInt32LE(8),
|
||||
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 (crc32(targetBlock) !== footerData.crc32) throw 'DVPLCRC32Mismatch';
|
||||
if (targetBlock.length !== footerData.cSize) {
|
||||
throw new RangeError('DVPL size mismatch');
|
||||
}
|
||||
if (crc32(targetBlock) !== footerData.crc32) {
|
||||
throw new TypeError('DVPL CRC32 mismatch');
|
||||
}
|
||||
if (footerData.type === 0) {
|
||||
if (!(footerData.oSize === footerData.cSize && footerData.type === 0)) {
|
||||
throw 'DVPLTypeSizeMismatch';
|
||||
throw new RangeError('DVPL type and size mismatch');
|
||||
}
|
||||
|
||||
return targetBlock;
|
||||
@@ -39,11 +43,11 @@ export async function readDVPL(file: string) {
|
||||
const DecompressedBlockSize = decodeBlock(targetBlock, deDVPLBlock);
|
||||
|
||||
if (DecompressedBlockSize !== footerData.oSize) {
|
||||
throw 'DVPLDecodeSizeMismatch';
|
||||
throw new RangeError('Decompressed DVPL size mismatch');
|
||||
}
|
||||
|
||||
return deDVPLBlock;
|
||||
} else {
|
||||
throw new TypeError('Unknown DVPL format');
|
||||
throw new SyntaxError('Unknown DVPL format');
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user