BackupPC-XS

 view release on metacpan or  search on metacpan

lib/BackupPC/XS.pm  view on Meta::CPAN

#
use constant BPC_FTYPE_FILE     => 0;
use constant BPC_FTYPE_HARDLINK => 1;
use constant BPC_FTYPE_SYMLINK  => 2;
use constant BPC_FTYPE_CHARDEV  => 3;
use constant BPC_FTYPE_BLOCKDEV => 4;
use constant BPC_FTYPE_DIR      => 5;
use constant BPC_FTYPE_FIFO     => 6;
use constant BPC_FTYPE_SOCKET   => 8;
use constant BPC_FTYPE_UNKNOWN  => 9;
use constant BPC_FTYPE_DELETED  => 10;

my @FILE_TYPES = qw(
                  BPC_FTYPE_FILE
                  BPC_FTYPE_HARDLINK
                  BPC_FTYPE_SYMLINK
                  BPC_FTYPE_CHARDEV
                  BPC_FTYPE_BLOCKDEV
                  BPC_FTYPE_DIR
                  BPC_FTYPE_FIFO
                  BPC_FTYPE_SOCKET
                  BPC_FTYPE_UNKNOWN
                  BPC_FTYPE_DELETED
             );

# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.

# This allows declaration	use BackupPC::XS ':all';
# If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
# will save memory.

@EXPORT    = qw( );

@EXPORT_OK = (
                  @FILE_TYPES,
             );

%EXPORT_TAGS = (
    'all'    => [ @EXPORT_OK ],
);

our $VERSION = '0.62';

require XSLoader;
XSLoader::load('BackupPC::XS', $VERSION);

# Preloaded methods go here.

#
# If $compress is >0, copy and compress $srcFile putting the output
# in $destFileZ.  Otherwise, copy the file to $destFileNoZ, or do
# nothing if $destFileNoZ is undef.  Finally, if rename is set, then
# the source file is removed.
#
sub compressCopy
{
    my($srcFile, $destFileZ, $destFileNoZ, $compress, $rmSrc) = @_;
    my($srcFh);
    my(@s) = stat($srcFile);
    my $atime = $s[8];
    my $mtime = $s[9];

    if ( $compress > 0 ) {
        my $fh = BackupPC::XS::FileZIO::open($destFileZ, 1, $compress);
        my $data;
        if ( defined($fh) && open($srcFh, "<", $srcFile) ) {
            binmode($srcFh);
            while ( sysread($srcFh, $data, 65536 *4) > 0 ) {
                $fh->write(\$data);
            }
            close($srcFh);
            $fh->close();
            unlink($srcFile) if ( $rmSrc );
            utime($atime, $mtime, $destFileZ);
            return 1;
        } else {
            $fh->close() if ( defined($fh) );
            return 0;
        }
    }
    return 0 if ( !defined($destFileNoZ) );
    if ( $rmSrc ) {
        return rename($srcFile, $destFileNoZ);
    } else {
        return 0 if ( !copy($srcFile, $destFileNoZ) );
        utime($atime, $mtime, $destFileNoZ);
    }
}

1;
__END__
# Below is stub documentation for your module. You'd better edit it!

=head1 NAME

BackupPC::XS - Perl extension for BackupPC libraries

=head1 SYNOPSIS

  use BackupPC::XS;
  use BackupPC::XS qw( :all );

=head1 DESCRIPTION

BackupPC::XS provides various submodules that implement various BackupPC library functions.
The following sections describe each submodule.

This documentation is very terse.  BackupPC::XS is not intended to be a general-purpose
module - it is closely tied to BackupPC.  Look in the BackupPC code to see examples of
using this module.

=head2 BackupPC::XS::FileZIO

Compressed file I/O using zlib:

    $fd = BackupPC::XS::FileZIO::open($fileName, $writeFlag, $compressLevel);
    $fd = BackupPC::XS::FileZIO::fdopen($stream, $writeFlag, $compressLevel);
    $nWrite   = $fd->write($dataRef);
    $nRead    = $fd->read($dataRef, $maxRead);



( run in 1.535 second using v1.01-cache-2.11-cpan-39bf76dae61 )