Skip to content

Commit 91474c6

Browse files
apply suggestions from comments
Co-authored-by: Lyndon White <[email protected]>
1 parent 896d4bc commit 91474c6

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/fileio.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function loadfile(T, file::File)
99
end
1010

1111
function loadfile(T, file::TextFile)
12-
_ignore_crlf(read(file.filename, String))
12+
_ignore_linefeed(read(file.filename, String))
1313
end
1414

1515
function loadfile(::Type{<:Number}, file::File{format"TXT"})
@@ -41,7 +41,7 @@ end
4141
# Some target formats are not supported by FileIO and thus require an encoding/compression process
4242
# before saving. For other formats, we should trust IO backends and make as few changes as possible.
4343
# Otherwise, reference becomes unfaithful. The encoding process helps making the actual data matches
44-
# the reference data, which is load from reference file via IO backends.
44+
# the reference data, which is loaded from reference file via IO backends.
4545
#
4646
# TODO: split `maybe_encode` to `maybe_preprocess` and `maybe_encode`
4747
"""
@@ -54,9 +54,9 @@ If there is no known method to encode `x`, then it directly return `x` without w
5454
maybe_encode(::Type{<:DataFormat}, x; kw...) = x
5555

5656
# plain TXT
57-
maybe_encode(::Type{DataFormat{:TXT}}, x; kw...) = _ignore_crlf(string(x))
57+
maybe_encode(::Type{DataFormat{:TXT}}, x; kw...) = _ignore_linefeed(string(x))
5858
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractArray{<:AbstractString}; kw...) = _join(x)
59-
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractString; kw...) = _ignore_crlf(x)
59+
maybe_encode(::Type{DataFormat{:TXT}}, x::AbstractString; kw...) = _ignore_linefeed(x)
6060
maybe_encode(::Type{DataFormat{:TXT}}, x::Number; kw...) = x # TODO: Change this to string(x) ?
6161

6262
function maybe_encode(
@@ -74,7 +74,7 @@ end
7474

7575
# SHA256
7676
maybe_encode(::Type{DataFormat{:SHA256}}, x; kw...) = _sha256(string(x))
77-
maybe_encode(::Type{DataFormat{:SHA256}}, x::AbstractString) = _sha256(_ignore_crlf(x))
77+
maybe_encode(::Type{DataFormat{:SHA256}}, x::AbstractString) = _sha256(_ignore_linefeed(x))
7878
maybe_encode(::Type{DataFormat{:SHA256}}, x::AbstractArray{<:AbstractString}) = _sha256(_join(x))
7979
function maybe_encode(::Type{DataFormat{:SHA256}}, img::AbstractArray{<:Colorant}; kw...)
8080
# encode image into SHA256
@@ -86,6 +86,6 @@ end
8686

8787

8888
# Helpers
89-
_join(x::AbstractArray{<:AbstractString}) = mapreduce(_ignore_crlf, (x,y)->x*"\n"*y, x)
89+
_join(x::AbstractArray{<:AbstractString}) = _ignore_linefeed(join(x, "\n"))
9090
_sha256(x) = bytes2hex(sha256(x))
91-
_ignore_crlf(x::AbstractString) = replace(x, "\r"=>"")
91+
_ignore_linefeed(x::AbstractString) = replace(x, "\r"=>"")

0 commit comments

Comments
 (0)