-
-
Notifications
You must be signed in to change notification settings - Fork 56
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix post-Elixir 1.16 divergence in File.stream! * Add exclusion for PhilomenaWeb.Config compile-time variance * Add missing Autocomplete.t
- Loading branch information
Showing
3 changed files
with
25 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
defmodule Philomena.Sha512 do | ||
@spec file(String.t()) :: String.t() | ||
def file(file) do | ||
@chunk_size 10_485_760 | ||
|
||
@spec file(Path.t()) :: String.t() | ||
def file(path) do | ||
hash_ref = :crypto.hash_init(:sha512) | ||
|
||
File.stream!(file, [], 10_485_760) | ||
path | ||
|> stream_file() | ||
|> Enum.reduce(hash_ref, &:crypto.hash_update(&2, &1)) | ||
|> :crypto.hash_final() | ||
|> Base.encode16(case: :lower) | ||
end | ||
|
||
if Version.match?(System.version(), ">= 1.16.0") do | ||
# `stream!/2` was added in Elixir 1.16 to accept a shortened form, | ||
# where we only need to specify the size of each stream chunk | ||
defp stream_file(file) do | ||
File.stream!(file, @chunk_size) | ||
end | ||
else | ||
# Use legacy stream/3 for older Elixir versions | ||
defp stream_file(file) do | ||
File.stream!(file, [], @chunk_size) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters