Skip to content

Commit

Permalink
Merge pull request #81 from lukaskasa/main
Browse files Browse the repository at this point in the history
Improve WebP Format Detection in Data Extension
  • Loading branch information
yeatse authored Sep 16, 2024
2 parents f55b0ab + d80ff41 commit 3e985c9
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions Sources/Image+WebP.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,12 @@ extension Data {
return false
}

let endIndex = index(startIndex, offsetBy: 12)
let testData = subdata(in: startIndex..<endIndex)
guard let testString = String(data: testData, encoding: .ascii) else {
return false
}
let riffHeader = subdata(in: startIndex..<index(startIndex, offsetBy: 4))
let webpHeader = subdata(in: index(startIndex, offsetBy: 8)..<index(startIndex, offsetBy: 12))

if testString.hasPrefix("RIFF") && testString.hasSuffix("WEBP") {
return true
} else {
return false
}
let riffString = String(data: riffHeader, encoding: .ascii)
let webpString = String(data: webpHeader, encoding: .ascii)

return riffString == "RIFF" && webpString == "WEBP"
}
}

0 comments on commit 3e985c9

Please sign in to comment.