Add fs.size() (#4)

This commit is contained in:
Paul Liverman III 2018-03-16 20:19:05 -07:00 committed by GitHub
parent 3616fc80e5
commit e918bbe5f1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

21
fs.moon
View File

@ -1,10 +1,23 @@
exists = (file_path) ->
handle = io.open file_path, "r"
if handle
handle\close!
if file = io.open file_path, "r"
file\close!
return true
return false
else
return false
size = (file_or_path) ->
if "string" == type file_or_path
file = io.open file_or_path, "r"
size = file\seek "end"
file\close!
return size
else
current = file\seek!
size = file\seek "end"
file\seek "set", current
return size
{
:exists
:size
}