[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Merge data and resource fork



After Paul Schinder's remark I looked at POSIX::Open and came up with the
following code.

Thanks all for your help.

----------

#!perl -w

# mergeForks.plx

# Merge the data fork of one file and resource fork of another file
# Rene Laterveer, 13-jul-2000

use POSIX;
use Fcntl;
use Mac::Files;

my $buf = '';

my $fileinData = "DataFork";
my $fileinRsrc = "RsrcFork";
my $fileOut = "MergedFile";

# Create output file
Mac::Files::FSpCreate($fileOut,'????','DATA');

# Copy Resource Fork
my $fdout = POSIX::open($fileOut, &POSIX::O_WRONLY | &POSIX::O_TRUNC |
&Fcntl::O_RSRC);
my $fdin = POSIX::open($fileinRsrc, &POSIX::O_RDONLY | &Fcntl::O_RSRC);
while (POSIX::read($fdin, $buf, 2048) > 0) {
    POSIX::write($fdout, $buf, 2048);
}
POSIX::close($fdin);
POSIX::close($fdout);

# Copy Data Fork
open DATAFORKOUT, ">$fileOut" or die "$fileOut: $!";
open DATAFORKIN, $fileinData or die "$fileinData: $!";
while (read(\*DATAFORKIN, $buf, 2048)) {
    print DATAFORKOUT $buf;
}
close DATAFORKIN;
close DATAFORKOUT;

__END__



___
Rene' Laterveer                   laterveer@mac.com


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org