mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Rewrite CREReader:ZipContentExt() function.
Technically, the only serious problem in this function was the code:
local tmp = assert(io.popen('unzip -l \"'..fname..'\"', "r"))
while tmp do
s = tmp:read("*line")
if i > 3 then tmp:close(); break; end
i = i + 1
end
It is meaningless to evaluate the truth of the return value of assert()
and the above code gives the impression that it relies on the
(undocumented and unreliable) fact that after tmp:close() tmp will be
nil, even though in actual fact it does because it breaks out of the
loop.
However, having looked at the function I saw that the whole thing
can be rewritten in a much simpler way:
local tmp = assert(io.popen('unzip -l \"'..fname..'\" | head -4 | tail -1', "r"))
s = tmp:read("*line")
tmp:close()
This commit is contained in:
@@ -35,19 +35,16 @@ function CREReader:init()
|
||||
self.default_font = default_font
|
||||
end
|
||||
end
|
||||
|
||||
-- inspect the zipfile content
|
||||
function CREReader:ZipContentExt(fname)
|
||||
local i, s = 1
|
||||
local tmp = assert(io.popen('unzip -l \"'..fname..'\"', "r"))
|
||||
while tmp do
|
||||
s = tmp:read("*line")
|
||||
if i > 3 then tmp:close(); break; end
|
||||
i = i + 1
|
||||
end
|
||||
local tmp = assert(io.popen('unzip -l \"'..fname..'\" | head -4 | tail -1', "r"))
|
||||
s = tmp:read("*line")
|
||||
tmp:close()
|
||||
return s and string.lower(string.match(s, ".+%.([^.]+)"))
|
||||
end
|
||||
|
||||
|
||||
-- open a CREngine supported file and its settings store
|
||||
function CREReader:open(filename)
|
||||
local ok
|
||||
|
||||
Reference in New Issue
Block a user