Skip Menu |

This queue is for tickets about the Archive-Zip CPAN distribution.

Report information
The Basics
Id: 66163
Status: open
Priority: 0/
Queue: Archive-Zip

People
Owner: Nobody in particular
Requestors: DETI [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in: (no value)
Fixed in: (no value)



Is there a way to know the size of the final zip file?

When I want to send the zip to a browser via

$zip->writeToFileHandle( 'STDOUT' );

I need to send a HTTP header before. In that header I want to put the Content-length. That is the reason why I need to know the size before I write it to STDOUT.
Subject: How to get the size of the final zip before writing it?
I wrote a ugly workaround for now, but I would appreciate a better implemented solution. Thanks!




Show quoted text
# Open an anonymous temporary filehandle
open( my $MEMORY, "+>", undef ) || die "Can not open anonymous temporary file: $!";
Show quoted text
# write zip in anonymous temporary filehandle $MEMORY
$zip->writeToFileHandle( $MEMORY );


Show quoted text
# print http header
print $CGI_Simple->header(
   -type => 'application/octet-stream',
   -attachment => 'my_zip.zip',
   -Content_length => tell $MEMORY, # get size of zip out of anonymous temporary filehandle $MEMORY
   -expires => 'now',
);

Show quoted text
# print zip to STDOUT
seek( $MEMORY, 0, 0 );
print <$MEMORY>;
close( $MEMORY );


Subject: re: knowing the size of zip files for HTTP transfer
On Fri Feb 25 05:51:17 2011, DETI wrote: Show quoted text
> Is there a way to know the size of the final zip file? > > When I want to send the zip to a browser via > > $zip->writeToFileHandle( 'STDOUT' ); > > I need to send a HTTP header before. In that header I want to put the > Content-length. That is the reason why I need to know the size before > I write > it to STDOUT.
Can't you use chunked encoding (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6)?
Subject: Re: How to get the size of the final zip before writing it?
On Thu Mar 10 09:50:25 2011, NEDKONZ wrote: 
Show quoted text
> Can't you use chunked encoding (see  
> http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html#sec3.6)?

I can't see how. Even with "Transfer-Encoding: chunked" you need to know the size of each (!) chunk in advance. See example in
http://en.wikipedia.org/wiki/Chunked_transfer_encoding#Example