Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 2 additions & 17 deletions lua/image/utils/magic.lua
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,6 @@ local function read_file_header(file, num_bytes)
return content and { content:byte(1, #content) } or nil
end

local function has_jpeg_end_signature(file)
if not file then return false end
local size = file:seek("end")
if size < 2 then return false end
file:seek("set", size - 2)
local end_signature = file:read(2)
return end_signature == "\xFF\xD9", nil
end

local function check_signature_match(header, format, signature)
local bytes = { signature:byte(1, #signature) }
local match = true
Expand Down Expand Up @@ -70,14 +61,8 @@ M.detect_format = function(path)

for format, signature in pairs(image_signatures) do
if check_signature_match(header, format, signature) then
if format == "jpeg" then
local is_jpeg = has_jpeg_end_signature(file)
file:close()
return is_jpeg and format or nil
else
file:close()
return format
end
file:close()
return format
end
end

Expand Down