#!/usr/bin/perl
use strict;
use warnings;
use IO::Async::Loop;
use Net::Async::Webservice::S3;
use Getopt::Long;
GetOptions(
'b|byte-range=s' => \my $BYTE_RANGE,
) or exit 1;
my $loop = IO::Async::Loop->new;
my %config = do {
open my $rc, "<", ".s3rc" or die "Cannot read .s3rc config - $!\n";
map { chomp; m/^(.*?)=(.*)$/ } <$rc>;
};
my ( $bucket, $prefix ) = split m{/}, ( $config{bucket} || die "Could not find 'bucket' in config\n" ), 2;
my $s3 = Net::Async::Webservice::S3->new(
access_key => ( $config{access_key} || die "Could not find 'access_key' in config\n" ),
secret_key => ( $config{secret_key} || die "Could not find 'secret_key' in config\n" ),
ssl => $config{ssl},
bucket => $bucket,
prefix => $prefix,
);
$loop->add( $s3 );
$s3->get_object(
key => shift @ARGV,
byte_range => $BYTE_RANGE,
on_chunk => sub {
my ( undef, $chunk ) = @_;
print $chunk;
},
)->get;