checksum calculation for file offsets

Discussion in 'Perl Misc' started by Ironhide, Apr 26, 2010.

  1. Ironhide

    Ironhide Guest

    Hi,

    This is what I am trying to achieve.

    Create a copy of a file.
    User inputs starting offset and end offset for the file.
    For this range the perl program should calculate the md5sum
    for both the original file and the copied file and compare them
    both.

    Any idea how to go about dealing with the offsets?
     
    Ironhide, Apr 26, 2010
    #1
    1. Advertising

  2. Ironhide <> wrote:
    >Create a copy of a file.
    >User inputs starting offset and end offset for the file.
    >For this range the perl program should calculate the md5sum
    >for both the original file and the copied file and compare them
    >both.
    >
    >Any idea how to go about dealing with the offsets?


    All the MD5 modules I have seen accept text as input. So just read those
    parts from both files and then run the MD5 algorithm on the extracted
    text.

    jue
     
    Jürgen Exner, Apr 26, 2010
    #2
    1. Advertising

  3. Ironhide

    Steve C Guest

    Ironhide wrote:
    > Hi,
    >
    > This is what I am trying to achieve.
    >
    > Create a copy of a file.
    > User inputs starting offset and end offset for the file.
    > For this range the perl program should calculate the md5sum
    > for both the original file and the copied file and compare them
    > both.
    >
    > Any idea how to go about dealing with the offsets?



    Digest::perl::MD5 is a pure perl implementation. You could hack
    the addfile method to add optional start and end offset arguments.
    It would just add a seek to start, and only read end-start bytes
    instead of to end of file. (Off-by-one error left to the astute).

    If you need better performance use the addfile method for
    Digest::MD5. Rather than hack C source and rebuild, it might be
    easier to read from STDIN. In bash this would be:

    dd if=myfile ibs=1 skip=$START count=$(( $END - $START )) | mymd5sum.pl
     
    Steve C, Apr 27, 2010
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Phillip Farber
    Replies:
    0
    Views:
    429
    Phillip Farber
    Aug 20, 2003
  2. mikegw
    Replies:
    5
    Views:
    389
    Nick Keighley
    May 24, 2004
  3. Andrus
    Replies:
    3
    Views:
    804
    Flash Gordon
    Oct 13, 2005
  4. Robert Dodier
    Replies:
    2
    Views:
    174
    Tad McClellan
    Jul 9, 2006
  5. Ironhide
    Replies:
    5
    Views:
    150
    Xho Jingleheimerschmidt
    Mar 26, 2011
Loading...

Share This Page