Re: File Size Limit
Hi James, please reply to all recipients. On Fri, 8 Apr 2016 10:47:57 +0100 James Kerwinwrote: > Good morning/afternoon all (depending on where you are), > > This should be a quick one: > > When creating files in a perl script is there a way to limit the size of > the file created? If somebody could give me a term to search for that > should be enough. > > I have googled this but I can't find an answer. I'm probably not using the > right search terms because this seems very do-able and I'm surprised to > have not found anything. > > My situation is as follows: > > I perform some text manipulation on files that are 30 MB in size. > The newly formatted files get pushed to another script that can only handle > files of 5MB maximum. > > So I would like to be able to limit the file size and start a new one when > it reaches (or comes close to) this limit. This would allow me to automate > it rather than having to manually break the big files up before continuing. > You can tell the current position in the file using http://perldoc.perl.org/functions/tell.html and write some logic to handle it. There's also http://perldoc.perl.org/functions/truncate.html . One option would be to use a custom file handle (see perldoc perltie) but that may be much slower than implementing it in a higher-level. Hope it helps. Regards, Shlomi > Thanks! > James. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
File Size Limit
Good morning/afternoon all (depending on where you are), This should be a quick one: When creating files in a perl script is there a way to limit the size of the file created? If somebody could give me a term to search for that should be enough. I have googled this but I can't find an answer. I'm probably not using the right search terms because this seems very do-able and I'm surprised to have not found anything. My situation is as follows: I perform some text manipulation on files that are 30 MB in size. The newly formatted files get pushed to another script that can only handle files of 5MB maximum. So I would like to be able to limit the file size and start a new one when it reaches (or comes close to) this limit. This would allow me to automate it rather than having to manually break the big files up before continuing. Thanks! James.
File Size Limit in Archive::Perl
Hi All, Is there any way to limit the file size while zipping using Archive::Zip so that it will stop processing a zip operation on a file list when it crosses the maximum file size. Thanks in advance. -A -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: File Size Limit in Archive::Perl
San wrote: Is there any way to limit the file size while zipping using Archive::Zip so that it will stop processing a zip operation on a file list when it crosses the maximum file size. Hey San Unfortunately Archive::Zip requires that an archive be written to disk before the compression is performed and the final size can be determined. But it is possible to compress files individually and write them to a temporary file to determine their size, and then add the same archive member to the final archive without repeating the compression. Take a look at the program below, which is written for a Windows system but should be easily portable. HTH, Rob use strict; use warnings; use Archive::Zip qw/AZ_OK/; use File::Temp qw/tempfile/; use constant MB = 1024 * 1024; my $dir = 'C:'; my @files = do { opendir my $fd, $dir\\ or die $! or die $!; grep -f, map $dir\\$_, readdir $fd; }; my $zip = Archive::Zip-new; my $total; my $limit = 50*MB; foreach my $file (@files) { my $temp = Archive::Zip-new; my $member = $temp-addFile($file); next unless $member-compressedSize; my $fh = tempfile(); $temp-writeToFileHandle($fh) == AZ_OK or die $!; $zip-addMember($member); $total += $member-compressedSize; die $total bytes exceeds archive size limit if $total $limit; } print Total archive size: $total bytes\n\n; $zip-writeToFileNamed('archive.zip') == AZ_OK or die $!; -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/