Mirrana
Mirrana

Reputation: 1731

checking crc32 of a file

This is not really a "how to" question.

Is there a "standard" file structure that applications use to store the checksums of files in a folder? I'm developing a tool to check various things like crc32, md5, sha1, sha256, etc... I'd like to have my program store the various hashes in files in the folder of what I'm checking.

I know that there is a file commonly used called 'md5sums' or 'sha1sums'. But what about CRC? I haven't noticed any around. And if there is, what's the structure of it?

Thanks.

Upvotes: 1

Views: 1516

Answers (3)

Mirrana
Mirrana

Reputation: 1731

Here's what I was looking for. This is generated by the program QuickSFV:

; Generated by QuickSFV v2.36 on 2012-08-09 at 16:34:25
; http://www.QuickSFV.org
;
;   1684525442  21:45.33 2012-08-05 Video.mkv
Video.mkv 9AC44069

I was looking for a format that seems standard for using with other programs that aim to accomplish the same purpose.

Upvotes: 0

Jeremy Adsitt
Jeremy Adsitt

Reputation: 434

I might consider taking a look at the bit torrent files as a start. I think it uses a JSON like style

If you have a torrent program you can generate a .torrent file for a folder and the contents and check it out

I think this uses a concatenated SHA1 hash of parts of a file but you could just concatenate multiple hashes in it's place, and have then length encoded.

Wikipedia has the following example: http://en.wikipedia.org/wiki/Torrent_file

{
    'announce': 'http://tracker.site1.com/announce',
    'info':
    {
        'name': 'directoryName',
        'piece length': 262144,
        'files':
        [
            {'path': ['111.txt'], 'length': 111},
            {'path': ['222.txt'], 'length': 222}
        ],
        'pieces': '6a8af7eda90ba9f851831073c48ea6b7b7e9feeb...8a43d9d965a47f75488d3fb47d2c586337a20b9f'
    }
}

I would probably modify it to be something like:

{
    'datelastupdated': '[date hash program ran]',
    'info':
    {
        'name': 'thedirectoryName',
        'Totalfiles': 2,
        'Totaldirs': 2,
        'files':
        [
            {'name': '111.txt', 'size': 111, 'md5':"df038ad...", 'sha1':'3323...},
            {'name': '222.txt', 'size': 222 ........ etc.}
        ],
        'dirs':
        [
            {'name': 'directoryname'},
            {'name': 'othername'}
        ]

    }
}

You can then use a package to do json_encoding or decoding (php from cli will work for this) or whatever you want to create/update them..

this structure would allow you to access it conveniently after doing a json_decode something like:

$decodedjson->info->files[x]->name

I always get a bit confused w/ that syntax, so it might be something like $decodedjson->info['files'][x]->name , but hopefully you get the idea, it would be easy to loop across the structure, update it compare, and save it.. Cheers!

Upvotes: 1

Kamran Amini
Kamran Amini

Reputation: 1062

MD5 hashes uses another file to store the hash value for a file. You can use a similar method to store different CRCs calculated for your files.

Upvotes: 0

Related Questions