Idea: file:consult/2 that takes usual file modes?

I’m most particularly wanting to be able to run file:consult("myfile.gz", [compressed]). At the moment, the options as I see it for dealing with a compressed file are:

  1. read the file in and write it back out as uncompressed
  2. shell out to os:cmd("gunzip myfile.gz")
  3. reimplement consult/1 and the unexported consult_stream/1

I suspect having the option of passing read_ahead would also be desirable. I’m not sure which other modes would be particularly useful, but it seems reasonable to me accept [mode()] as an optional Opts parameter.

-spec consult(Filename, Opts) -> {ok, Terms} | {error, Reason} when
      Filename :: name_all(),
      Opts :: [mode()],
      Terms :: [term()],
      Reason :: posix() | badarg | terminated | system_limit
              | {Line :: integer(), Mod :: module(), Term :: term()}.
2 Likes

I struggled with this a while ago. I made some changes to my setup utility, but ultimately went another way, since it didn’t solve the whole problem (I still ended up with dependencies that didn’t know to use my special hack, and crashed trying the normal file:consult())

It turned out that, at least for my purposes, very little change was needed to file_io_server, in order to at least support file:consult/1 et al from within .ez archives.

https://github.com/uwiger/setup/pull/59/files

1 Like