FileCmp provides the function filecmp, which returns true if two files are equal byte by byte.
This code is adapted from an example in this Discourse post.
Only filecmp is exported.
julia> using FileCmp
julia> filecmp("path1", "path2")
truefilecmp is similar to the Python function
filecmp.cmp
but provides more information, as does the Unix/Linux/GNU
command cmp.
filecmp(path1::AbstractString, path2::AbstractString, bufsize=0; info=Val(false); limit=0)
filecmp(io1::IO, io2::IO, bufsize=0; info=Val(false), limit=0)
- Return
trueifpath1andpath2are equal byte by byte. Otherwise returnfalse. - If either file does not exist an exception is thrown.
- If
infoistrue, then return an instance ofFileCmp.Infoinstead ofBool. The instance ofFileCmp.Infois then queried with functionsfiles_equal,bytes_read, andgot_eofto get information similar to Unixcmp. - The keyword argument
infomay be one oftrue,false,Val(true), orVal(false). The latter two are supported in case the application requires the return type to be inferrable. - If
limitis greater than zero, then read at mostlimitbytes. - The files are read into buffers of
bufsizebytes. Ifbufsize=0, then a default is used.
FileCmp.files_equal(info::FileCmp.Info)
Return true if the files compared to produce info are the byte-for-byte equal.
The following is always true:
filecmp(p1, p2; info=false) == files_equal(filecmp(p1, p2; info=true))
got_eof(info::FileCmp.Info)::Int
Return -1 if first file is a prefix of the second one. That is,
an EOF occured on the first file, but not the second, and all compared bytes were equal.
Return 1 if the reverse happened. Otherwise, return 0.
bytes_read(info::Info)
The number of bytes read from each file before either differing bytes were found, or EOF on one or both files.