Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow reading gzip compressed schemas #82

Open
ivanov opened this issue Mar 19, 2024 · 0 comments
Open

allow reading gzip compressed schemas #82

ivanov opened this issue Mar 19, 2024 · 0 comments

Comments

@ivanov
Copy link

ivanov commented Mar 19, 2024

thanks again for Exonerate! I mentioned the issue of working with compressed (gzipped) schemas at CodeBEAM America, and Isaac suggested I open an issue.

I have a bunch of schemas that are wordy but compress nicely (5-6x smaller). I currently end up generating the validators like this (code and names have been changed and simplified to protect the innocent).

defmodule CompressedReaderHelper do
  defmacro __using__(_env) do
    res = File.stream!(Path.join(__DIR__, "schema.json.gz"), [:read, :compressed]) |> Enum.into("")
    quote do
      require Exonerate
      Exonerate.function_from_string( :def, :function_name, unquote(res))
    end
  end
end

(I actually wrote it this way so I could use CompressedReaderHelper and pass some extra parameters to change the schema file path for different modules, but that's not pertinent to the compression).

I think it would be pretty straightforward to conditionally pass the :compressed option and replace File.read! with File.stream! in function_from_file

defmacro function_from_file(type, function_name, path, opts) do

but I am not experienced enough in Elixir to know if it's stylistically a poor choice to push this into the opts parameter that's already there but used for an entirely different set of options.

@ivanov ivanov changed the title allow reading compressed schemas allow reading gzip compressed schemas Mar 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant