Skip to main content
added 184 characters in body
Source Link
jason
  • 242.6k
  • 35
  • 436
  • 532

I was just wondering if there is a fast way to do this without having to manually go in and read the file.

Not really.   

If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same and so you will still have to do a byte by byte comparison). 

However, hashes (tend to) use all the bytes in the file, so no matter what, you at some point have to read the filefiles byte for byte. And in fact, comparingjust a straight byte forby byte comparison will be faster than computing a checksum orhash. This is because a hash or anything like that (again, they readreads all the bytes just like comparing byte by byte-by-byte does, AND theybut hashes do some other computations that add time and. Additionally, a byte by byte-by-byte comparison can terminate early on the first pair of non-equal bytes). And finally

Finally, you can not avoid the need for a byte by byte-by-byte read. If the hashes are equal, that doesn't mean the files are equal. In this case you still have to compare byte by byte-by-byte.

Not really.  If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same). However, hashes (tend to) use all the bytes in the file, so no matter what, you have to read the file byte for byte. And in fact, comparing byte for byte will be faster than computing a checksum or a hash or anything like that (again, they read all the bytes just like comparing byte by byte does, AND they do some other computations that add time and a byte by byte comparison can terminate early on the first pair of non-equal bytes). And finally, you can not avoid the need for a byte by byte read. If the hashes are equal, that doesn't mean the files are equal. In this case you still have to compare byte by byte.

I was just wondering if there is a fast way to do this without having to manually go in and read the file.

Not really. 

If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same and so you will still have to do a byte by byte comparison). 

However, hashes use all the bytes in the file, so no matter what, you at some point have to read the files byte for byte. And in fact, just a straight byte by byte comparison will be faster than computing a hash. This is because a hash reads all the bytes just like comparing byte-by-byte does, but hashes do some other computations that add time. Additionally, a byte-by-byte comparison can terminate early on the first pair of non-equal bytes.

Finally, you can not avoid the need for a byte-by-byte read. If the hashes are equal, that doesn't mean the files are equal. In this case you still have to compare byte-by-byte.

added 184 characters in body
Source Link
jason
  • 242.6k
  • 35
  • 436
  • 532

Not really. If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same). However, hashes (tend to)1 use all the bytes in the file, so no matter what, you have to read the file byte for byte. And in fact, comparing byte for byte will be faster than computing a checksum or a hash or anything like that (again, they read all the bytes just like comparing byte by byte does, AND they do some other computations that add time and a byte by byte comparison can terminate early on the first pair of non-equal bytes). And finally, you can not avoid the need for a byte by byte read. If the hashes are equal, that doesn't mean the files are equal. In this case you still have to compare byte by byte.

Not really. If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same). However, hashes (tend to)1 use all the bytes in the file, so no matter what, you have to read the file byte for byte. And in fact, comparing byte for byte will be faster than computing a checksum or a hash or anything like that (again, they read all the bytes just like comparing byte by byte does, AND they do some other computations that add time).

Not really. If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same). However, hashes (tend to) use all the bytes in the file, so no matter what, you have to read the file byte for byte. And in fact, comparing byte for byte will be faster than computing a checksum or a hash or anything like that (again, they read all the bytes just like comparing byte by byte does, AND they do some other computations that add time and a byte by byte comparison can terminate early on the first pair of non-equal bytes). And finally, you can not avoid the need for a byte by byte read. If the hashes are equal, that doesn't mean the files are equal. In this case you still have to compare byte by byte.

Source Link
jason
  • 242.6k
  • 35
  • 436
  • 532

Not really. If the files came with hashes, you could compare the hashes, and if they are different you can conclude the files are different (same hashes, however, does not mean the files are the same). However, hashes (tend to)1 use all the bytes in the file, so no matter what, you have to read the file byte for byte. And in fact, comparing byte for byte will be faster than computing a checksum or a hash or anything like that (again, they read all the bytes just like comparing byte by byte does, AND they do some other computations that add time).