Daniel Friesel > App-Hashl > App::Hashl

Download:
App-Hashl-1.00.tar.gz

Dependencies

Annotate this POD

View/Report Bugs
Module Version: 1.00   Source  

NAME ^

App::Hashl - Partially hash files, check if files are equal etc.

SYNOPSIS ^

    use App::Hashl;

    my $hashl = App::Hashl->new();
    # or: App::Hashl->new_from_file($database_file);

VERSION ^

This manual documents App::Hashl version 1.00

DESCRIPTION ^

App::Hashl contains utilities to hash the first n bytes of files, store and recall them, check if another file is already in the database and optionally ignore file hashes.

METHODS ^

$hashl = App::Hashl->new(%conf)

Returns a new App::Hashl object. Accepted parameters are:

read_size => bytes

How many bytes of a file to consider for the hash. Defaults to 4 MiB (4 * 2**20 bytes).

$hashl = App::Hashl->new_from_file($file)

Returns the App::Hashl object saved to file by a prior $hashl->save call.

$hashl->si_size($bytes)

Returns bytes as a human-readable SI-size, such as "1.0k", "50.7M", "2.1G". The returned string is always six characters long.

$hashl->hash_file($file)

Returns the SHA1 hash of the first few bytes (as configured via read_size) of file. Dies if file cannot be read.

$hashl->hash_in_db($hash)

Checks if hash is in the database. If it is, returns the filename it is associated with. If it is ignored, returns "// ignored" (subject to change). Otherwise, returns false.

$hashl->file_in_db($file)

Checks if file's hash is in the database. For the return value, see hash_in_db.

$hashl->read_size()

Returns the current read size. Note that once an App::Hashl object has been created, it is not possible to change the read size.

$hashl->file($name)

Returns a hashref describing the file. The layout is as follows:

    hash => file's hash,
    mtime => mtime as UNIX timestamp,
    size => file size in bytes

If name does not exist in the database, returns undef.

$hashl->delete_file($name)

Remove the file from the database.

$hashl->files()

Returns a list of all file names in the database.

$hashl->add_file(%data)

Add a file to the database. Required keys in %data are:

file => name

relateve file name to store in the database

path => path

Full path to the file

unignore => 0|1

If true: do not skip ignored files, unignore and re-add them instead

If the file already is in the database, it is only updated if both the file size and the mtime have changed.

Returns true if the file was actually added to the database, false if it is ignored or already present (and up-to-date).

$hashl->ignored()

Returns a list of all ignored file hashes.

$hashl->ignore($file, $path)

Removes $file from the database and adds $path to the list of ignored file hashes.

$hashl->unignore($path)

Unignore the hash of $path.

$hashl->save($file)

Save the App::Hashl object with all data to $file. It can later be retrieved via new_from_file.

DIAGNOSTICS ^

None.

DEPENDENCIES ^

Digest::SHA(3pm);

BUGS AND LIMITATIONS ^

None known.

AUTHOR ^

Copyright (C) 2011 by Daniel Friesel <derf@finalrewind.org>

LICENSE ^

  0. You just DO WHAT THE FUCK YOU WANT TO.
syntax highlighting: