mirror of
https://github.com/koreader/koreader.git
synced 2025-12-24 12:14:05 +01:00
md5: centralize and deduplicate (#11003)
Document partial md5 hash is calculated by util.partialMD5() and stored in doc_settings as "partial_md5_checksum" on the first document opening.
This commit is contained in:
@@ -9,7 +9,6 @@ local Math = require("optmath")
|
||||
local TileCacheItem = require("document/tilecacheitem")
|
||||
local lfs = require("libs/libkoreader-lfs")
|
||||
local logger = require("logger")
|
||||
local util = require("util")
|
||||
|
||||
--[[
|
||||
This is an abstract interface to a document
|
||||
@@ -144,31 +143,6 @@ function Document:discardChange()
|
||||
self.is_edited = false
|
||||
end
|
||||
|
||||
-- calculate partial digest of the document and store in its docsettings to avoid document saving
|
||||
-- feature to change its checksum.
|
||||
function Document:fastDigest(docsettings)
|
||||
if not self.file then return end
|
||||
local file = io.open(self.file, 'rb')
|
||||
if file then
|
||||
local tmp_docsettings = false
|
||||
if not docsettings then -- if not provided, open/create it
|
||||
docsettings = require("docsettings"):open(self.file)
|
||||
tmp_docsettings = true
|
||||
end
|
||||
local result = docsettings:readSetting("partial_md5_checksum")
|
||||
if not result then
|
||||
logger.dbg("computing and storing partial_md5_checksum")
|
||||
result = util.partialMD5(file)
|
||||
docsettings:saveSetting("partial_md5_checksum", result)
|
||||
end
|
||||
if tmp_docsettings then
|
||||
docsettings:close()
|
||||
end
|
||||
file:close()
|
||||
return result
|
||||
end
|
||||
end
|
||||
|
||||
-- this might be overridden by a document implementation
|
||||
function Document:getNativePageDimensions(pageno)
|
||||
local hash = "pgdim|"..self.file.."|"..pageno
|
||||
|
||||
Reference in New Issue
Block a user