@@ -9,7 +9,7 @@ function loadfile(T, file::File)
99end
1010
1111function loadfile (T, file:: TextFile )
12- _ignore_crlf (read (file. filename, String))
12+ _ignore_linefeed (read (file. filename, String))
1313end
1414
1515function loadfile (:: Type{<:Number} , file:: File{format"TXT"} )
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
5454maybe_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))
5858maybe_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)
6060maybe_encode (:: Type{DataFormat{:TXT}} , x:: Number ; kw... ) = x # TODO : Change this to string(x) ?
6161
6262function maybe_encode (
7474
7575# SHA256
7676maybe_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))
7878maybe_encode (:: Type{DataFormat{:SHA256}} , x:: AbstractArray{<:AbstractString} ) = _sha256 (_join (x))
7979function maybe_encode (:: Type{DataFormat{:SHA256}} , img:: AbstractArray{<:Colorant} ; kw... )
8080 # encode image into SHA256
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