in reply to Re: Problem in sending "tar" files as attachment using MIME::Lite module
in thread Problem in sending "tar" files as attachment using MIME::Lite module

hi,

I think problem is with creating the Tar file. I am using the code as below:
my $tar = Archive::Tar->new(); my @filelist = ("txt.del", "txt1.del"); $tar->add_files(@filelist); $tar->write("newpart.tar", 2); my $error = $tar->error(); print "error is $error \n";
By using the $tar->write("newpart.tar", 2);, I am getting the error as "Invalid archive directory".
But to use the $tar->write("newpart.tar");, the tar file size is very large.

So which compression value can be used such that the tar file size will be less and will open without errors.

Thank you,
Santhi

Replies are listed 'Best First'.
Re^3: Problem in sending "tar" files as attachment using MIME::Lite module
by graff (Chancellor) on Dec 20, 2006 at 09:24 UTC
    You could try opening the output file first, using PerlIO::gzip so that it gets compressed on output, then pass the file handle to Archive::Tar->write() -- something like this:
    use PerlIO::gzip; use Archive::tar; # ... open( my $tarfh, ">:gzip", "my_tarball.tar.gz" ); # ... $tar->write( $tarfh );
    (I haven't tried that myself, but that's what I would try.)

    UPDATE: (2010-10-18) It seems that PerlIO::gzip should be viewed as superseded by PerlIO::via:gzip. (see PerlIO::gzip or PerlIO::via::gzip).

Re^3: Problem in sending "tar" files as attachment using MIME::Lite module
by derby (Abbot) on Dec 20, 2006 at 12:03 UTC

    That error is not coming from your code snippet, correct? Is it coming from winzip (or some other extraction program) when you try to extract it? I wonder if your extraction program is barfing because it doesn't know how to handle the decompression. If you're going to compress the archive, you should name it either newpart.tar.gz or newpart.tgz. Then your extraction program may be better able to handle it or at least you've let others know the archive needs to be unzipped first. And if your mailing compressed, I wouldn't use the application/tar mime type, application/x-gtar would probably work better.

    -derby