Digital Mages

Digital Mages - Paranoid::IO::FileMultiplexer::Block(3)

Paranoid::IO::FileMultiplexer::Block

Section: User Contributed Perl Documentation (3)
Updated: 2021-12-28
Index  

NAME

Paranoid::IO::FileMultiplexer::Block - Block-level Allocator/Accessor  

VERSION

$Id: lib/Paranoid/IO/FileMultiplexer/Block.pm, 2.09 2021/12/28 15:46:49 acorliss Exp $  

SYNOPSIS

    $obj = Paranoid::IO::FileMultiplexer::Block->new(
            $filename, $bnum, $bsize);
    $rv  = $obj->allocate;

    $bn   = $obj->blockNum;
    $bs   = $obj->blockSize;
    $minp = $obj->minPos;
    $maxp = $obj->maxPos;

    $bytesWritten = $obj->bwrite($content);
    $bytesWritten = $obj->bwrite($content, $start );
    $bytesWritten = $obj->bwrite($content, $start, $length );
    $bytesWritten = $obj->bwrite($content, $start, $length, $offset );
    $bytesRead    = $obj->bread(\$content);
    $bytesRead    = $obj->bread(\$content, $start, $bytes);
    $bytesRead    = $obj->bread(\$content, undef, $bytes);
    $bytesRead    = $obj->bread(\$content, $start, $bytes);

    $support64 = $obj->test64;

    $rv = $obj->recalibrate;

 

DESCRIPTION

This class is not meant to be used directly, but as part of the Paranoid::IO::FileMultiplexer functionality. It is primarily a base class from which other critical classes are derived.

This module does presume that whatever file it is being used on has already been opened in the appropriate mode, and that the Paranoid::IO flock stack has been enabled. For the purposes of Paranoid::IO::FileMultiplexer, this is done in that class.  

SUBROUTINES/METHODS

 

new

    $obj = Paranoid::IO::FileMultiplexer::Block->new(
            $filename, $bnum, $bsize);

This creates a new instance of a block object. It requires the filename in order to retrieve the cached file handle from Paranoid::IO, the number of the block (using zero-based indexing), and the size of the block. It will block size and the block number to calculate its actual position within the file.  

blockNum

    $bn = $obj->blockNum;

This method returns the object's assigned block number.  

blockSize

    $bs = $obj->blockSize;

This method returns the object's assigned block size.  

minPos

    $minp = $obj->minPos;

This method returns the minimum file position for the block.  

maxPos

    $maxp = $obj->maxPos;

This method returns the maximum file position for the block.  

allocate

    $rv = $obj->allocate;

This method attempts to allocate the block on the file system, and returns a boolean indicating its success. This method will fail if you attempt to allocate a block that's already been allocated, or a block whose file position is beyond the current end of the file. In other words, blocks must be allocated in sequence.  

recalibrate

    $rv = $obj->recalibrate;

This method recalculates minimum/maximum file position based on the currently set block size. This should always be called after any change to blockSize.  

bwrite

    $bytesWritten = $obj->bwrite($content);
    $bytesWritten = $obj->bwrite($content, $start );
    $bytesWritten = $obj->bwrite($content, $start, $length );
    $bytesWritten = $obj->bwrite($content, $start, $length, $offset );

This method writes the passed content to the block, while making sure that the content does not overflow the block boundaries. If the start position of the write is omitted, it writes from the beginning of the block. If the start position is provided, note that this is the position relative to the block, not the file. That means you would specify values from a range of o to (blockSize - 1).

This method is intentionally designed to allow you to pass more content than will fit inside of a block, and yet only write as much as will fit within the block. The calling code should use the return value to figure out what remains to be written in other blocks, as needed.  

bread

    $bytesRead = $obj->bread(\$content);
    $bytesRead = $obj->bread(\$content, $start);
    $bytesRead = $obj->bread(\$content, undef, $bytes);
    $bytesRead = $obj->bread(\$content, $start, $bytes);

This method reads the content of the block, while making sure that the content read does not go beyond the borders of the block. If the start position of the read is omitted, it reads from the beginning of the block. Like bwrite, this position is relative to the beginning of the block, not the file.

This method is also intentionally designed to allow you to request more data than can fit within the block, yet returning only what the block contains. The calling code should use the return value to figure out what remains to be read from other blocks, as needed.  

has64bInt

    $rv = $obj->has64bInt;

this method returns a boolean value denoting whether the running platform supports 64b integers.  

splitInt

    ($lower, $upper) = $obj->splitInt($num);

This method splits an integer into two 32b values, the first being the lower 32b, and the second being the upper 32b. The second value will always be zero if the running platform does not support 64b integers.  

joinInt

    $i = $obj->joinInt($lower, $upper);

This method takes two 32b integers and joins them into a single 64b integer. If the running platform only supports 32b integers and the upper value is non-zero, this method will return undef.  

DEPENDENCIES

o
Fcntl
o
Paranoid
o
Paranoid::Debug
o
Paranoid::IO
 

BUGS AND LIMITATIONS

 

AUTHOR

Arthur Corliss (corliss@digitalmages.com)  

LICENSE AND COPYRIGHT

This software is free software. Similar to Perl, you can redistribute it and/or modify it under the terms of either:

  a)     the GNU General Public License
         <https://www.gnu.org/licenses/gpl-1.0.html> as published by the 
         Free Software Foundation <http://www.fsf.org/>; either version 1
         <https://www.gnu.org/licenses/gpl-1.0.html>, or any later version
         <https://www.gnu.org/licenses/license-list.html#GNUGPL>, or
  b)     the Artistic License 2.0
         <https://opensource.org/licenses/Artistic-2.0>,

subject to the following additional term: No trademark rights to ``Paranoid'' have been or are conveyed under any of the above licenses. However, ``Paranoid'' may be used fairly to describe this unmodified software, in good faith, but not as a trademark.

(c) 2005 - 2021, Arthur Corliss (corliss@digitalmages.com) (tm) 2008 - 2021, Paranoid Inc. (www.paranoid.com)


 

Index

NAME
VERSION
SYNOPSIS
DESCRIPTION
SUBROUTINES/METHODS
new
blockNum
blockSize
minPos
maxPos
allocate
recalibrate
bwrite
bread
has64bInt
splitInt
joinInt
DEPENDENCIES
BUGS AND LIMITATIONS
AUTHOR
LICENSE AND COPYRIGHT