增加获取文件大小
This commit is contained in:
@@ -125,6 +125,16 @@ M.exists_file = function(filepath)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- 取文件大小
|
||||||
|
M.file_size = function(filepath)
|
||||||
|
local file = io.open(filepath, "rb")
|
||||||
|
if not file then
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
local size = file:seek("end")
|
||||||
|
file:close()
|
||||||
|
return size
|
||||||
|
end
|
||||||
-- 取近N个月时间
|
-- 取近N个月时间
|
||||||
M.recent_months = function(n)
|
M.recent_months = function(n)
|
||||||
local mons = {}
|
local mons = {}
|
||||||
@@ -292,4 +302,44 @@ M.traverse_dir = function(dirpath)
|
|||||||
end
|
end
|
||||||
return files
|
return files
|
||||||
end
|
end
|
||||||
|
-- 数组是否一致(不考虑顺序)
|
||||||
|
-- 只考虑 string 和 number/integer 类型,其它类型忽略
|
||||||
|
M.array_equal = function(a, b)
|
||||||
|
-- 辅助函数:判断是否为有效类型(string 或 number)
|
||||||
|
local function is_valid_type(v)
|
||||||
|
return type(v) == "string" or type(v) == "number"
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 统计数组中有效类型元素的值及其出现次数
|
||||||
|
local function count_values(arr)
|
||||||
|
local counts = {}
|
||||||
|
for _, v in ipairs(arr) do
|
||||||
|
if is_valid_type(v) then
|
||||||
|
local key = tostring(v) -- 统一转换为字符串作为key
|
||||||
|
counts[key] = (counts[key] or 0) + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return counts
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 统计两个数组的有效元素
|
||||||
|
local counts_a = count_values(a)
|
||||||
|
local counts_b = count_values(b)
|
||||||
|
|
||||||
|
-- 检查 counts_a 中的所有键值对是否在 counts_b 中匹配
|
||||||
|
for key, count in pairs(counts_a) do
|
||||||
|
if counts_b[key] ~= count then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- 检查 counts_b 中的所有键值对是否在 counts_a 中匹配
|
||||||
|
for key, count in pairs(counts_b) do
|
||||||
|
if counts_a[key] ~= count then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
return M
|
return M
|
||||||
Reference in New Issue
Block a user