From 953048331c789fa21b8ea2047e1dbf844e8f3276 Mon Sep 17 00:00:00 2001 From: dgvncsz0f Date: Wed, 28 Feb 2024 12:42:05 -0300 Subject: [PATCH 1/2] fix: dialyzer Type check fails when using Elixir 1.16. --- lib/multipart/part.ex | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/multipart/part.ex b/lib/multipart/part.ex index 75a3aad..3cfcc1c 100644 --- a/lib/multipart/part.ex +++ b/lib/multipart/part.ex @@ -35,7 +35,7 @@ defmodule Multipart.Part do @spec file_body(String.t(), headers()) :: t() def file_body(path, headers \\ []) do %File.Stat{size: size} = File.stat!(path) - file_stream = File.stream!(path, [{:read_ahead, 4096}], 1024) + file_stream = File.stream!(path, 1024) %__MODULE__{body: file_stream, content_length: size, headers: headers} end From 0c3334e7f65c818e1e7cae6fad5c9e6e183353b9 Mon Sep 17 00:00:00 2001 From: dgvncsz0f Date: Fri, 1 Mar 2024 08:28:39 -0300 Subject: [PATCH 2/2] add support for older elixir versions --- lib/multipart/part.ex | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/multipart/part.ex b/lib/multipart/part.ex index 3cfcc1c..154a2b5 100644 --- a/lib/multipart/part.ex +++ b/lib/multipart/part.ex @@ -35,7 +35,7 @@ defmodule Multipart.Part do @spec file_body(String.t(), headers()) :: t() def file_body(path, headers \\ []) do %File.Stat{size: size} = File.stat!(path) - file_stream = File.stream!(path, 1024) + file_stream = file_stream!(path, 1024) %__MODULE__{body: file_stream, content_length: size, headers: headers} end @@ -180,4 +180,10 @@ defmodule Multipart.Part do defp maybe_add_filename_directive(directives, false, _path) do directives end + + if Version.compare(System.version(), "1.16.0") in [:gt, :eq] do + defp file_stream!(path, bytes), do: File.stream!(path, bytes) + else + defp file_stream!(path, bytes), do: File.stream!(path, [], bytes) + end end