modularml / mojo

The Mojo Programming Language
https://docs.modular.com/mojo/manual/
Other
23.36k stars 2.6k forks source link

[Feature Request] Basic Filesystem Module #306

Closed lsh closed 1 year ago

lsh commented 1 year ago

Review Mojo's priorities

What is your request?

Right now there are several cases where having the filesystem would be useful.
This is particularly the case for any kind of parsing (and people in the community are playing with formats like Arrow or CSV right now).
I don't think there is a need for robust I/O right now, but having the following would be nice:

- Path + PathRef (similar to String)
- Directory
  - does not actually need to expose the pointer, just need a way to get cwd and children
- File
  - preferably with a `read_to_string` and `read_to_dyanmic_vector[UI8]`

Eventually there should be async versions of all of these operations, but that's more a long term goal.

What is your motivation for this change?

Right now any notebooks that plays around with parsing binary data or working with text files requires pasting the data directly into a cell and storing it in a variable.
Uploading and reading a file directly can often be preferable (especially in the binary case).

Any other details?

No response

ksandvik commented 1 year ago

Most likely depends on a trait/protocol system, same with any other std libraries. There's also the option that std libraries are not part of the mojo system, rather included via open source.

Mogball commented 1 year ago

I think we can start a basic IO/fs module without traits. It's mostly non-parametric code. fyi @abduld

ksandvik commented 1 year ago

Oh interesting, I assume there would be (default) traits for Read, Write, Open, and sub-traits like how to read buffers, bytes and so on....

lsh commented 1 year ago

@ksandvik those are all things that are important long term, but the major ask here is just a method (something like):

fn read_path_to_string(path: StringRef) -> String

Which should simplify some experiments in the playground.

abduld commented 1 year ago

We need to order this correctly. The first step before this is to enhance the String type to support UTF encoding first. So, we want to tackle that before starting work on file system

crisadamo commented 1 year ago

Hey, I have an initial implementation of kind of "libc" in mojo. Still working on it, will see if I can upload it over the weekend. It basically allow you to use sockets, and read files, etc. I need to finish the FileSystem struct implementation and will upload to my github.

jackos commented 1 year ago

Feature added in 0.4.0