mirror of
https://github.com/koreader/koreader.git
synced 2025-08-10 00:52:38 +00:00
Update KOSyncClient
This commit is contained in:
@@ -99,7 +99,10 @@ function Document:discardChange()
|
||||
self.is_edited = false
|
||||
end
|
||||
|
||||
-- calculate partial digest of the document
|
||||
-- calculate partial digest of the document and store in its docsettings to avoid document saving
|
||||
-- feature to change its checksum.
|
||||
--
|
||||
-- To the calculating mechanism itself.
|
||||
-- since only PDF documents could be modified by KOReader by appending data
|
||||
-- at the end of the files when highlighting, we use a non-even sampling
|
||||
-- algorithm which samples with larger weight at file head and much smaller
|
||||
@@ -109,23 +112,31 @@ end
|
||||
-- 1048576, 4194304, 16777216, 67108864, 268435456 or 1073741824, appending data
|
||||
-- by highlighting in KOReader may change the digest value.
|
||||
function Document:fastDigest()
|
||||
local md5 = require("ffi/MD5")
|
||||
local lshift = bit.lshift
|
||||
if not self.file then return end
|
||||
local file = io.open(self.file, 'rb')
|
||||
if file then
|
||||
local step, size = 1024, 1024
|
||||
local m = md5.new()
|
||||
for i = -1, 10 do
|
||||
file:seek("set", lshift(step, 2*i))
|
||||
local sample = file:read(size)
|
||||
if sample then
|
||||
m:update(sample)
|
||||
else
|
||||
break
|
||||
local docsettings = require("docsettings"):open(self.file)
|
||||
local result = docsettings:readSetting("partial_md5_checksum")
|
||||
if not result then
|
||||
local md5 = require("ffi/MD5")
|
||||
local lshift = bit.lshift
|
||||
local step, size = 1024, 1024
|
||||
local m = md5.new()
|
||||
for i = -1, 10 do
|
||||
file:seek("set", lshift(step, 2*i))
|
||||
local sample = file:read(size)
|
||||
if sample then
|
||||
m:update(sample)
|
||||
else
|
||||
break
|
||||
end
|
||||
end
|
||||
result = m:sum()
|
||||
docsettings:saveSetting("partial_md5_checksum", result)
|
||||
end
|
||||
docsettings:close()
|
||||
file:close()
|
||||
return m:sum()
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user