Check md5 compressed file without decompressing it completely

I want to check the integrity of a Ubuntu disk backup copied from dd to a Windows share. There is not enough space to unpack the backup. Is there a utility for calculating the md5 compressed file without decompressing it completely?

+4
source share
2 answers

It:

gzip -d -c myfile.gz | md5sum 

will transfer the unpacked content to md5sum, and not load it all into memory.

+11
source

A simple answer using gzip / zcat and piping to md5sum (which was already published when I wrote this) will work, but if you want more fun, here is a short Perl script that will do the same.

 #!/usr/bin/perl use strict; use warnings; use Archive::Zip qw/:ERROR_CODES :CONSTANTS/; use Digest::MD5; die "Usage: $0 zipfile filename" unless @ARGV == 2; my $zipfile = $ARGV[0]; my $filename = $ARGV[1]; my $z = Archive::Zip->new(); die "Error reading $zipfile" unless $z->read($zipfile) == AZ_OK; my $member = $z->memberNamed($filename); die "Could not find $filename in $zipfile" unless $member; $member->desiredCompressionMethod(COMPRESSION_STORED); $member->rewindData(); my $md5 = Digest::MD5->new; while(1) { my($buf,$status) = $member->readChunk(); $md5->add($$buf) if $status == AZ_STREAM_END || $status == AZ_OK; last if $status == AZ_STREAM_END; die "IO Error" if $status != AZ_OK; } my $digest = $md5->hexdigest; print "$digest $zipfile/$filename\n"; 
+2
source

All Articles