12 ms·
I'm curious, why did the author read only on three sections for each file? is related on how CRC32 works?
by yandrypozo 5y ago
I'm curious, why did the author read only on three sections for each file? is related on how CRC32 works?
- unnouinceput 5y agoNo. CRC32 doesn't care what you throw at it. It is related to speed of building a "database", for lack of a better word, of the file. Instead of CRC32 entire file, you just get chunks of it, increasing the speed. However this approach it's definitely flawed as there are plenty of file types that have the beginning and the end identical, so only the readings/CRC32 of the middle section might be actually useful. But CRC32 has a lower space hence collisions have higher chance to happen. The better approach might be, for same size files, to just Seek(FileSize div 2) and read 32 bytes from there. If those are identical with another file then start a full file comparison until one character diverges then stop. If multiple files are having these same middle bytes then maybe do, for each file, a full SHA256 and compare those. Also, as other commenters pointed, you might have same info but meta is different (videos, pictures, etc) so that needs to be implemented as well.
- magicalhippo 5y agoI wrote my own duplicate file finder way back in the days. I did the obvious trick of binning by size before trying to compute any hashes, and was mildly surprised to find how few out of my ~million files had exactly the same size. For multiple files with identical size I just did the full file MD5, we only had HDD's back then and we all know how much they like random access.
- unnouinceput 5y agoI wrote one too, over 20 years ago. Still works, that .exe, even today. Unsurprisingly I was using CRC32 too. When I look at the code that is there I cringe, such is the mess there. Oh well, everyone has to start somewhere.
- selcuka 5y agoIt is to save time by not reading the whole file for files larger than `thresholdFileSize`. The code calls it fuzzy hash. The author says that they tested it on 172K+ files and it's safe, but I still wouldn't trust it enough to delete files from my filesystem.
- m-manu 5y agoThe tool doesn't delete anything -- just reports. If you're uncomfortable with "fuzzy hash", use the -thorough cmd line option.
- selcuka 5y agoA better implementation could be to perform a full hash (not CRC32 though; maybe even a byte-by-byte comparison) when the fuzzy hashes match, which is a small probability anyway.