mojo icon indicating copy to clipboard operation
mojo copied to clipboard

[Feature Request] Basic Filesystem Module

Open lsh opened this issue 1 year ago • 5 comments

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

lsh avatar Jun 02 '23 00:06 lsh

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.

ksandvik avatar Jun 02 '23 00:06 ksandvik

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

Mogball avatar Jun 05 '23 21:06 Mogball

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....

ksandvik avatar Jun 05 '23 22:06 ksandvik

@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.

lsh avatar Jun 06 '23 01:06 lsh

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

abduld avatar Jun 06 '23 18:06 abduld

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.

crisadamo avatar Jun 09 '23 00:06 crisadamo

Feature added in 0.4.0

jackos avatar Oct 05 '23 20:10 jackos