Stas Bekman <[EMAIL PROTECTED]> writes: [...]
> Moving $b->remove to the end makes the code horribly kludgy. It's > better to change the idiom to step through the buckets instead of > removing them. Adjusting John's sample code: > > my $bb = $r->upload('file')->bb(); > open(OUT,">/tmp/test_file"); > for (my $b = $bb->first; $b; $b = $bb->next($b)) { > $b->read(my $data); > print OUT $data; > } > close OUT; > > Joe, does this idiom work fine with file buckets? In principle this is fine, but there is a practical issue to consider: this idiom has the effect of reading the file bucket back into memory until there are no more file buckets left in the brigade. If the upload was large enough to warrant a spool file to begin with, slurping it all back into memory as chunks is not a good idea. What I'm going to recommend in the Apache::Upload docs is ask people to use the TIEHANDLE api for io() instead: my $io = $req->upload("foo")->io; print while read $io, $_, 8000; # read() will manage the buckets for you > We need to write a test for this case, but at the moment we have no > API to create file buckets. I guess we could test that in an output > filter and have a response handler call sendfile, which should create > a bucket of file type. > > BTW, John you could also do: > > my $bb = $r->upload('file')->bb(); > my $len = $bb->flatten(my $data); > print OUT $data; > > though it's probably less memory-usage effective. Hah, aren't *you* the guy that asked for $upload->slurp(my $data)? Now you're recommending $upload->bb->flatten, which does exactly the same thing (deja vu?). So, can we go back and get rid of slurp() now? :-) -- Joe Schaefer -- Report problems: http://perl.apache.org/bugs/ Mail list info: http://perl.apache.org/maillist/modperl.html List etiquette: http://perl.apache.org/maillist/email-etiquette.html