From 1d6d863bd20f148fb5ccec7cc9e274722a160f0f Mon Sep 17 00:00:00 2001 From: Izaya Date: Wed, 3 May 2017 17:53:33 +1000 Subject: [PATCH] some filesystem util functions like copy and move and stuff --- modules/library/fs-util.lua | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 modules/library/fs-util.lua diff --git a/modules/library/fs-util.lua b/modules/library/fs-util.lua new file mode 100644 index 0000000..a7b5ea5 --- /dev/null +++ b/modules/library/fs-util.lua @@ -0,0 +1,30 @@ +function fcopy(i,o) + local f1,f2 = fopen(i,"rb"),fopen(o,"wb") + if f1 and f2 then + local c=fread(f1,math.huge) + repeat + fwrite(f2,c) + c=fread(f1,math.huge) + until c == nil + fclose(f1) + fclose(f2) + return true + end + return false +end +function fmove(i,o) + fcopy(i,o) + frm(i) +end +function fload(i) + local f,s = fopen(i,"rb"),"" + if f then + local c=fread(f,math.huge) + repeat + s=s..c + c=fread(f,math.huge) + until c == nil + load(s) + end + return false +end