mojo
mojo copied to clipboard
[Feature Request] Add path.getsize or file.getsize methods
Review Mojo's priorities
- [X] I have read the roadmap and priorities and I believe this request falls within the priorities.
What is your request?
Mojo v0.4.0 now supports file
module, but it seems that we still need one essential function -- getsize
or filesize
With native Mojo file
module we have to load whole file into memory just to know its size.
var f_ = open(file_name, "r")
let data = f_.read()
let cp_size = data._buffer.size
What is your motivation for this change?
So far in llama2.🔥
we have to use workaround via Python.
let _os = Python.import_module("os")
let ff_size = _os.path.getsize(file_name)
let cp_size = string.atol(ff_size.to_string())
It's turned out newcomers to Mojo who are trying to run llama2 locally, got multiple issues because of misconfiguration with MOJO_PYTHON_LIBRARY
, etc.
It would be great to add getsize
or filesize
to file
or path
modules in the next release.
Any other details?
In Python it's implemented in path
module
let _os = Python.import_module("os")
let ff_size = _os.path.getsize(file_name)
I think it's worthwhile to implement the more general os.stat
, since fs_stat
must provide more details about file, but I'm not sure what are the concerns regarding platforms compatiblity.
# python alternatives
os.path.getsize()
os.stat()