this is a rather weird question.
In 3sl (ziggit link) I’d like to have a --hexdump flag that just dumps .. well .. the full hex range. The CLI parser, currently, returns a File, so that if no path is passed in it uses stdin. Maybe I should add a way to open multiple files but i digress.
Due to the way the CLI parser is structured I’d like to create a File that wraps the bytes 0x0 to 0xFF, and pass that out to the main logic of the program. Is this possible? Or do I need to change the logic so I pass out a Reader ?
It’d be easiest with a std.Io.Reader, but you can use memfd_create or similar on Linux to get a File.
1 Like
If your code does not depend on any File specific functionality, then it should indeed just take a *Io.Reader. It is just more flexible, especially for testing.
For cases where you truly do need a file, that use case isn’t currently by Io or its implementations, but in the future there should be an implementation that does, whether its in std or not I can’t say since Andrew seems to be against having a VFS implementation (there are other ways to get similar functionality).
I am not sure how compatible @cancername’s suggestion is with Io…
I do actually use File specific functionality to get the file length. It is not simple to rejig the code to return Reader.
Also I don’t want to use OS-specific API
Edit: I could use a union between a File and another thing but that feels like too much architecting tbh.
Maybe you could pass a length hint and a reader, would that work?
1 Like
Or you can just make the length a parameter…
Looks like it needs to be more concrete than a hint, its used to figure out where in the file to output, and one option is an offset from the end. Can’t do that with only a hint.
1 Like
Honestly returning a *std.Io.Reader would require a huge restructuring of the code that I am unwilling to do for what is essentially a demo/debug feature. Returning a File.Reader is less of a headache but then we’re back where we started.
I looked in the stdlib for creating a temp file but apparently there arent any.
1 Like