Reading the first MB of a binary file

M

Max Leason

Hi,

I'm attempting to read the first MB of a binary file and then do a md5
hash on it so that i can find the file later despite it being moved or
any file name changes that may have been made to it. These files are
large (350-1400MB) video files and i often located on a different
computer and I figure that there is a low risk for generating the same
hash between two files. The problem occurs in the read command which
returns all \x00s. Any ideas why this is happening?

Code:b'\x00\x00\x00\x00\x00\x00....\x00'
 
M

MRAB

Max said:
> Hi,
>
> I'm attempting to read the first MB of a binary file and then do a
> md5 hash on it so that i can find the file later despite it being
> moved or any file name changes that may have been made to it. These
> files are large (350-1400MB) video files and i often located on a
> different computer and I figure that there is a low risk for
> generating the same hash between two files. The problem occurs in the
> read command which returns all \x00s. Any ideas why this is
> happening?
>
> Code:
> b'\x00\x00\x00\x00\x00\x00....\x00'
>
You're reading the first 1024 bytes. Perhaps the first 1024 bytes of the
file _are_ all zero!

Try reading more and checking those, eg:
b'\x00' * SIZE
 
M

Marc 'BlackJack' Rintsch

I'm attempting to read the first MB of a binary file and then do a md5
hash on it so that i can find the file later despite it being moved or
any file name changes that may have been made to it. These files are
large (350-1400MB) video files and i often located on a different
computer and I figure that there is a low risk for generating the same
hash between two files. The problem occurs in the read command which
returns all \x00s. Any ideas why this is happening?

Code:
b'\x00\x00\x00\x00\x00\x00....\x00'

As MRAB says, maybe the first 1024 actually *are* all zero bytes. Wild
guess: That's a file created by a bittorrent client which preallocates
the files and that file above isn't downloaded completely yet!?

Ciao,
Marc 'BlackJack' Rintsch
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top