View Single Post
Old 08-22-2019, 01:35 AM   #9
dsyrock
Human being with feelings
 
dsyrock's Avatar
 
Join Date: Sep 2018
Location: China
Posts: 565
Default

Quote:
Originally Posted by Xenakios View Post
For example if you need to do the comparison between 2 files just once, it would be just the same to just directly compare the files at the byte level. That could even be faster than calculating the checksums because you can do an early exit from the comparison algorithm at the first difference between the files, while checksums require to go through the entire file.
So I tried to write a script like this

Code:
local file=io.open("e:\\1.wav", "rb")

local content=file:read("*all")

local len=content:len()

file:close()

local f1={}

for i=1, len do    --store each byte of file1

    local text=content:sub(i, i)

    table.insert(f1, text:byte(1))

end

local file=io.open("e:\\2.wav", "rb")

local content=file:read("*all")

local len=content:len()

file:close()

local f2={}

for i=1, len do    --store each byte of file2

    local text=content:sub(i, i)

    table.insert(f2, text:byte(1))

end

local diff=false

for k, v in pairs(f2) do

    if v~=f1[k] then

        diff=true

        break

    end

end

if diff then msg("They are different") else msg("They are the same") end
Is it the right way to compare two files?

Last edited by dsyrock; 08-22-2019 at 02:18 AM.
dsyrock is offline   Reply With Quote