How can I verify file integrity after creating zip files?
Asked by
Trillium
Hey everyone! I'm building a VB .Net WinForms app to archive project directories at work by copying files older than a year to a storage RAID. It works great, including a binary comparison of the source and copied files to ensure everything went smoothly before deleting the originals.
Next, I want to compress these archived directories into individual zip files using the built-in function in .NET: `System.IO.Compression.ZipFile.CreateFromDirectory(...)`. My questions are:
1. What's the best way to verify that the zipped files are accurate before I go ahead and delete the source files? I don't want to risk any file corruptions.
2. Are there other compression methods I should consider aside from zip? I did test out 7zip, but I'd like to keep everything integrated in one app unless there's a compelling reason not to.
Thanks!
Answers
For verification, just unzip the file and do a diff of the contents. It's simple and effective! If anything doesnโt match up, you'll know immediately.
Reply to this answer
There's a more reliable method involving checksums or hash values. Using these can help you verify file integrity before deleting anything. After zipping, generate a checksum for your files and then again after decompressing. If they match, youโre all good!
Reply to this answer
I've found that using zlib is a solid choice. It has built-in checksums that ensure data integrity when uncompressing. Youโll need to decompress the files to check if zlib reports any errors; if it doesnโt, you can be pretty sure the zipping process was successful.
Reply to this answer
You might also want to look into using a compressed file system, as it does some of what you're trying to accomplish. However, for portability and compatibility, sticking with zip files might be the better option. Theyโve stood the test of time and include CRC checks, giving you some peace of mind about data integrity.
Reply to this answer
You can decompress the zip file and use a tool like `diff` to compare the original files with the decompressed ones. If you're dealing with directories, just remember to use the `-r` flag for a recursive comparison! Alternatively, you could generate SHA256 checksums for the files before zipping and compare those checksums after unzipping to ensure everything matches.
Reply to this answer
Add your answer
Answers are reviewed before publication.
Related Discussions