3
3
-- Written by Cosmin Apreutesei. Public Domain.
4
4
5
5
local ffi = require ' ffi'
6
+ local fs = require ' fs'
6
7
local external_dir = require ' package.exedir'
7
8
local BBIN_PREFIX = ' Bbin_'
8
9
@@ -42,7 +43,6 @@ local function canopen_blob(file)
42
43
end
43
44
44
45
local function fs_open_blob (file )
45
- local fs = require ' fs'
46
46
local buf , sz = blob_data (file )
47
47
if not buf then return nil end
48
48
return fs .open_buffer (buf , sz )
@@ -95,7 +95,6 @@ function bundle.open_dir_listing(dir, s)
95
95
end
96
96
97
97
local function fs_dir_blob (dir )
98
- local fs = require ' fs'
99
98
return bundle .open_dir_listing (dir , load_blob (dir ))
100
99
end
101
100
@@ -111,11 +110,11 @@ local function load_file(file)
111
110
end
112
111
113
112
local function mmap_file (file )
114
- local s = load_file (file )
115
- if not s then return end
116
- -- TODO: use fs.mmap() here
117
- return { data = ffi . cast ( ' const void* ' , s ), size = # s ,
118
- close = function () local _ = s ; end }
113
+ local m , err = fs . map (file )
114
+ if not m then return nil , err end
115
+ m . data = ffi . cast ( ' const void* ' , m . addr )
116
+ m . close = m . free
117
+ return m
119
118
end
120
119
121
120
local function canopen_file (file )
@@ -125,12 +124,10 @@ local function canopen_file(file)
125
124
end
126
125
127
126
function fs_open_file (file )
128
- local fs = require ' fs'
129
127
return (fs .open (file ))
130
128
end
131
129
132
130
function fs_dir_file (dir )
133
- local fs = require ' fs'
134
131
if not fs .is (dir , ' dir' ) then return nil end
135
132
return fs .dir (dir )
136
133
end
0 commit comments