diff options
-rw-r--r-- | src/luarocks/fs/lua.lua | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/luarocks/fs/lua.lua b/src/luarocks/fs/lua.lua index 9da3875b..58dcf5c1 100644 --- a/src/luarocks/fs/lua.lua +++ b/src/luarocks/fs/lua.lua | |||
@@ -211,6 +211,36 @@ function fs_lua.modules(at) | |||
211 | return modules | 211 | return modules |
212 | end | 212 | end |
213 | 213 | ||
214 | function fs_lua.filter_file(fn, input_filename, output_filename) | ||
215 | local fd, err = io.open(input_filename, "rb") | ||
216 | if not fd then | ||
217 | return nil, err | ||
218 | end | ||
219 | |||
220 | local input, err = fd:read("*a") | ||
221 | fd:close() | ||
222 | if not input then | ||
223 | return nil, err | ||
224 | end | ||
225 | |||
226 | local output, err = fn(input) | ||
227 | if not output then | ||
228 | return nil, err | ||
229 | end | ||
230 | |||
231 | fd, err = io.open(output_filename, "wb") | ||
232 | if not fd then | ||
233 | return nil, err | ||
234 | end | ||
235 | |||
236 | local ok, err = fd:write(output) | ||
237 | fd:close() | ||
238 | if not ok then | ||
239 | return nil, err | ||
240 | end | ||
241 | |||
242 | return true | ||
243 | end | ||
214 | 244 | ||
215 | --------------------------------------------------------------------- | 245 | --------------------------------------------------------------------- |
216 | -- LuaFileSystem functions | 246 | -- LuaFileSystem functions |