diff options
| author | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-17 16:00:09 -0300 |
|---|---|---|
| committer | Hisham Muhammad <hisham@gobolinux.org> | 2018-07-18 11:24:07 -0300 |
| commit | f20f4cca65d6433cb354b584ee25339f152e72ec (patch) | |
| tree | b7f86d4e93b164383041c4d0d40b9b5c32995126 | |
| parent | 7108a8b6a1c2f2b6d629135fc797a5a0aa25f934 (diff) | |
| download | luarocks-f20f4cca65d6433cb354b584ee25339f152e72ec.tar.gz luarocks-f20f4cca65d6433cb354b584ee25339f152e72ec.tar.bz2 luarocks-f20f4cca65d6433cb354b584ee25339f152e72ec.zip | |
fs: add filter_file
| -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 |
