Skip to content

Commit

Permalink
chore: types and formatting cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
vHeemstra authored Aug 12, 2024
1 parent 8a2109f commit 9ba5bbf
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@ function convertToInt(bytes: Uint8Array) {
return bytes.reduce((value, byte) => (value << 8) + byte)
}

function isEqual(first, second, length = 4) {
function isEqual(
first: Uint8Array | number[],
second: Uint8Array | number[],
length = 4,
) {
while (length > 0) {
length--
if (first[length] !== second[length]) {
return false
}
}
return true;
return true
}

/**
Expand All @@ -32,15 +36,12 @@ const chunkTypes = {
imageData: [0x49, 0x44, 0x41, 0x54], // 'IDAT'
}

export default function isApng(buffer: Buffer | Uint8Array): boolean {
export default function isApng(buffer: Uint8Array): boolean {
const minChunkSize = headerSizes.LENGTH + headerSizes.TYPE + headerSizes.CRC

if (
!buffer ||
!(
(typeof Buffer !== 'undefined' && Buffer.isBuffer(buffer)) ||
buffer instanceof Uint8Array
) ||
!(buffer instanceof Uint8Array) ||
buffer.length < headerSizes.SIGNATURE + minChunkSize
) {
return false
Expand Down Expand Up @@ -72,7 +73,8 @@ export default function isApng(buffer: Buffer | Uint8Array): boolean {
return false
}

const nextChunkPosition = minChunkSize + convertToInt(buffer.subarray(0, headerSizes.LENGTH))
const nextChunkPosition =
minChunkSize + convertToInt(buffer.subarray(0, headerSizes.LENGTH))

buffer = buffer.subarray(nextChunkPosition)
}
Expand Down

0 comments on commit 9ba5bbf

Please sign in to comment.