AnyEvent::Digest - A tiny AnyEvent wrapper for Digest::*
version v0.0.5
use AnyEvent; use AnyEvent::Digest; my $ctx = AnyEvent::Digest->new('Digest::SHA', opts => [1], unit => 65536, backend => 'aio'); # In addition to that $ctx can be used as Digest::* object, you can call add*_async() methods $ctx->addfile_async($file)->cb(sub { # Do something like the followings my $ctx = shift->recv; print $ctx->hexdigest,"\n"; }); AE::cv->recv; # Wait
To calculate message digest for large files may take several seconds. It may block your program even if you use AnyEvent. This module is a tiny AnyEvent wrapper for Digest::* modules, not to block your program during digest calculation.
Digest::*
Default backend is to use AnyEvent::idle. You can choose IO::AIO backend. You need install IO::AIO and AnyEvent::AIO for IO::AIO backend.
AnyEvent::idle
In addition to the following methods, other methods are forwarded to the base module. So, you can use an object of this module as if it is an object of base module. However, addfile() calls recv() internally so that AnyEvent backend you use SHOULD supprot blocking wait. If you want to avoid blocking wait, you can use addfile_base() instead.
addfile()
recv()
addfile_base()
new($base, %args)
This is a constructor method. $base specifies a module name for base digest implementation, which is expected to be one of Digest::* modules. 'require' is called for the base module, so you don't have to do 'require' explicitly.
$base
'require'
Available keys of %args are as follows:
%args
opts
passed to $base::new as @{$args{opts}}. It MUST be an array reference.
$base::new
@{$args{opts}}
unit
specifies an amount of read unit for addfile(). Default to 65536 = 64KiB.
backend
specifies a backend module to handle asynchronous read. Available backends are 'idle' and 'aio'. Default to 'idle'.
'idle'
'aio'
add_async(@dat)
Each item in @dat are added by add($dat). Between the adjacent add(), other AnyEvent watchers have chances to run. It returns a condition variable receiving this object itself.
@dat
add($dat)
add()
addfile_async($filename)
addfile_async(*handle)
add() is called repeatedly read from $filename or *handle by the specified unit. Between the adjacent add(), other AnyEvent watchers have chances to run. It returns a condition variable receiving this object itself.
$filename
*handle
add_bits_async()
Same as add_bits(), except it returns a condition variable receiving this object itself.
add_bits()
CAUTION: Currerntly, other AnyEvent watchers have NO chance to run during this call.
This method uses blocking wait + addfile_async().
addfile_async()
Forwarded to addfile() in the base module. If you need to avoid blocking wait somewhere, this might be helpful. However, during the call, other AnyEvent watchers are blocked.
AnyEvent
AnyEvent::AIO
IO::AIO
Digest
Yasutaka ATARASHI <yakex@cpan.org>
This software is copyright (c) 2013 by Yasutaka ATARASHI.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.
To install AnyEvent::Digest, copy and paste the appropriate command in to your terminal.
cpanm
cpanm AnyEvent::Digest
CPAN shell
perl -MCPAN -e shell install AnyEvent::Digest
For more information on module installation, please visit the detailed CPAN module installation guide.