K
Klaus
Hi Perl programmers,
I am trying to write a Module (its name will be LWP::Chunk) to
read arbitrarily big http-files sequentially in small chunks.
Let me give an example:
With the existing module LWP::UserAgent, you can say:
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://search.cpan.org/');
With my new module LWP::Chunk (this module still needs to be written),
you would be able to say:
use LWP::Chunk;
my $ck = LWP::Chunk->new('http://search.cpan.org/', {csize => 1024,
timeout => 10});
my $container = '';
while ($ck->read_chunk) {
$container .= $ck->buffer;
# do whatever you want to do here,
# you are even allowed to go last;
}
if ($ck->there_was_an_error) {
die "There has been an error (code=".$ck->errcode.")";
}
# here we have the data in $container
The problem is that I am stuck with writing method $ck->read_chunk. (I
want to read the next chunk of 1024 bytes).
I had a look at LWP::Simple and at LWP::UserAgent, but I could not
find any code that allows to read the next 1024 bytes from 'http://
search.cpan.org/'. (I don't want to read the whole data in one go, I
rather want to read it in smaller chunks)
Can anybody point me to the LWP-internals (maybe LWP::UserAgent,
HTTP::Request, HTTP::Response, etc... ???) which reads a chunk of
data ?
Thanks in advance.
I am trying to write a Module (its name will be LWP::Chunk) to
read arbitrarily big http-files sequentially in small chunks.
Let me give an example:
With the existing module LWP::UserAgent, you can say:
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ua->timeout(10);
$ua->env_proxy;
my $response = $ua->get('http://search.cpan.org/');
With my new module LWP::Chunk (this module still needs to be written),
you would be able to say:
use LWP::Chunk;
my $ck = LWP::Chunk->new('http://search.cpan.org/', {csize => 1024,
timeout => 10});
my $container = '';
while ($ck->read_chunk) {
$container .= $ck->buffer;
# do whatever you want to do here,
# you are even allowed to go last;
}
if ($ck->there_was_an_error) {
die "There has been an error (code=".$ck->errcode.")";
}
# here we have the data in $container
The problem is that I am stuck with writing method $ck->read_chunk. (I
want to read the next chunk of 1024 bytes).
I had a look at LWP::Simple and at LWP::UserAgent, but I could not
find any code that allows to read the next 1024 bytes from 'http://
search.cpan.org/'. (I don't want to read the whole data in one go, I
rather want to read it in smaller chunks)
Can anybody point me to the LWP-internals (maybe LWP::UserAgent,
HTTP::Request, HTTP::Response, etc... ???) which reads a chunk of
data ?
Thanks in advance.