Mac-Finder-DSStore
view release on metacpan or search on metacpan
package Mac::Finder::DSStore;
=head1 NAME
Mac::Finder::DSStore - Read and write Macintosh Finder DS_Store files
=head1 DESCRIPTION
C<Mac::Finder::DSStore> provides a handful of functions for reading and
writing the desktop database files created by the Macintosh Finder.
=head1 FUNCTIONS
Many functions take a C<$store> argument which is the opened file as
an instance of L<Mac::Finder::DSStore::BuddyAllocator>, or a C<$block>
argument which is a specific block of the file as an instance of
L<Mac::Finder::DSStore::BuddyAllocator::Block>.
=cut
use strict;
use warnings;
use POSIX qw(ceil);
use Carp qw(croak);
use Fcntl;
require Exporter;
our($VERSION) = '1.00';
our(@ISA) = qw(Exporter);
our(@EXPORT_OK) = qw( getDSDBEntries putDSDBEntries writeDSDBEntries makeEntries );
our($testpoint);
=head2 @records = &Mac::Finder::DSStore::getDSDBEntries($store[, $callback])
Retrieves the "superblock" pointed to by the C<DSDB> entry in the store's table
of contents, and traverses the B-tree it points to, returning a list of
the records in the tree. Alternately, you can supply a callback which will
be invoked for each record, and C<getDSDBEntries> will return an empty list.
=cut
sub getBTreeRootblock {
my($store) = @_;
return $store->blockByNumber($store->{toc}->{DSDB})->read(20, 'N*');
}
sub getDSDBEntries {
my($file, $callback) = @_;
my(@retval);
$callback = sub { push(@retval, $_[0]); } unless defined $callback;
my($rootnode, $height, $nrec, $nnodes, $blksize) = &getBTreeRootblock($file);
my($n) = &traverse_btree($file, $rootnode, $callback);
warn "Header node count ($nrec) not equal to actual node count ($n)"
if $n != $nrec;
@retval;
}
=head2 &Mac::Finder::DSStore::putDSDBEntries($store, $arrayref)
C<$arrayref> must contain a correctly ordered list of
C<Mac::Finder::DSStore::Entry> objects. They will be evenly
organized into a B-tree structure and written to the C<$store>. If there is
an existing tree of records in the file already, it will be deallocated.
( run in 0.652 second using v1.01-cache-2.11-cpan-d8267643d1d )