Skip to content

Commit

Permalink
refactor: improve code readability
Browse files Browse the repository at this point in the history
  • Loading branch information
madtisa committed Aug 10, 2024
1 parent f9dacba commit 0390e9c
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,25 +38,22 @@ export default function isApng(buffer: Buffer | Uint8Array): boolean {
let firstIndex = 0
let secondIndex = 0
for (let i = 0; i < buffer.length; i++) {
if (
!foundFirst &&
(buffer[i] === sequences.animationControlChunk[firstIndex] ||
(firstIndex > 0 &&
((firstIndex = 0) ||
buffer[i] === sequences.animationControlChunk[firstIndex])))
) {
if (buffer[i] !== sequences.animationControlChunk[firstIndex]) {
firstIndex = 0
}

if (buffer[i] === sequences.animationControlChunk[firstIndex]) {
firstIndex++
if (firstIndex === sequences.animationControlChunk.length) {
return true
}
}

if (
buffer[i] === sequences.imageDataChunk[secondIndex] ||
(secondIndex > 0 &&
((secondIndex = 0) ||
buffer[i] === sequences.imageDataChunk[secondIndex]))
) {
if (buffer[i] !== sequences.imageDataChunk[secondIndex]) {
secondIndex = 0
}

if (buffer[i] === sequences.imageDataChunk[secondIndex]) {
secondIndex++
if (secondIndex === sequences.imageDataChunk.length) {
return false
Expand Down

0 comments on commit 0390e9c

Please sign in to comment.