11local M = {}
22
3+ local uv = vim .uv or vim .loop
4+
35--- @type boolean
4- M .is_windows = vim . loop .os_uname ().version :match (" Windows" )
6+ M .is_windows = uv .os_uname ().version :match (" Windows" )
57
68--- @type boolean
7- M .is_mac = vim . loop .os_uname ().sysname == " Darwin"
9+ M .is_mac = uv .os_uname ().sysname == " Darwin"
810
911--- @type string
1012M .sep = M .is_windows and " \\ " or " /"
2325--- @param filepath string
2426--- @return boolean
2527M .exists = function (filepath )
26- local stat = vim . loop .fs_stat (filepath )
28+ local stat = uv .fs_stat (filepath )
2729 return stat ~= nil and stat .type ~= nil
2830end
2931
@@ -59,10 +61,10 @@ M.read_file = function(filepath)
5961 if not M .exists (filepath ) then
6062 return nil
6163 end
62- local fd = vim . loop . fs_open (filepath , " r" , 420 ) -- 0644
63- local stat = vim . loop . fs_fstat (fd )
64- local content = vim . loop .fs_read (fd , stat .size )
65- vim . loop .fs_close (fd )
64+ local fd = assert ( uv . fs_open (filepath , " r" , 420 ) ) -- 0644
65+ local stat = assert ( uv . fs_fstat (fd ) )
66+ local content = uv .fs_read (fd , stat .size )
67+ uv .fs_close (fd )
6668 return content
6769end
6870
@@ -86,30 +88,31 @@ M.mkdir = function(dirname, perms)
8688 if not M .exists (parent ) then
8789 M .mkdir (parent )
8890 end
89- vim . loop .fs_mkdir (dirname , perms )
91+ uv .fs_mkdir (dirname , perms )
9092 end
9193end
9294
9395--- @param filename string
9496--- @param contents string
9597M .write_file = function (filename , contents )
9698 M .mkdir (vim .fn .fnamemodify (filename , " :h" ))
97- local fd = vim . loop . fs_open (filename , " w" , 420 ) -- 0644
98- vim . loop .fs_write (fd , contents )
99- vim . loop .fs_close (fd )
99+ local fd = assert ( uv . fs_open (filename , " w" , 420 ) ) -- 0644
100+ uv .fs_write (fd , contents )
101+ uv .fs_close (fd )
100102end
101103
102104--- @param filename string
103105M .delete_file = function (filename )
104106 if M .exists (filename ) then
105- vim . loop .fs_unlink (filename )
107+ uv .fs_unlink (filename )
106108 return true
107109 end
108110end
109111
110112--- @param filename string
111113--- @param obj any
112114M .write_json_file = function (filename , obj )
115+ --- @diagnostic disable-next-line param-type-mismatch
113116 M .write_file (filename , vim .json .encode (obj ))
114117end
115118
0 commit comments