rustyconover / net-amazon-s3

Use the Amazon S3 - Simple Storage Service from Perl
http://search.cpan.org/dist/Net-Amazon-S3/
Other
13 stars 37 forks source link

Ranged download doesn't work with get_filename or get_callback #129

Open juhaszp-uhu opened 8 months ago

juhaszp-uhu commented 8 months ago

Net::Amazon::S3::Client::Object::Range provides a way to download just a part of an object. This works with $object->range("bytes=0-1000")->get(). However, the get_filename and get_callback methods don't work, they don't do anything if range is used (they do work as $object's methods, though).

Complete example:


use Modern::Perl '2021';
use Net::Amazon::S3::Client;
use Data::Dumper;

my $aws_access_key_id = '...';
my $aws_secret_access_key = '...';
my $host = '...';
my $bucket_name = '...;
my $key = '...';

my $client = Net::Amazon::S3::Client->new (
        host                  => $host,
        aws_access_key_id     => $aws_access_key_id,
        aws_secret_access_key => $aws_secret_access_key,
        secure                => 0,
        retry                 => 0,
        error_handler_class   => 'Net::Amazon::S3::Error::Handler::Status',
);

my $bucket = $client->bucket( name => $bucket_name );

my $object;
$object = $bucket->object( key => $key);

$object->range('bytes=0-10000')->get_callback(sub {
        my $s = length($_[0]);
        print "chunk received, size $s\n";
        # do something with chunk
});

Also, get_callback is not documented at all for Net::Amazon::S3::Client::Object, and Net::Amazon::S3::Client::Object::Range is only rudimentarily documented.

juhaszp-uhu commented 8 months ago

I've found why it doesn't work: in Net::Amazon::S3::Object::Range you wrote my ($self, %args) = shift; -- that should be my ($self, %args) = @_;