Amazon-S3-Lite
view release on metacpan or search on metacpan
lib/Amazon/S3/Lite.pm view on Meta::CPAN
my @st = stat $data;
$content_length = $st[7] if @st && defined $st[7];
}
}
croak 'content_length is required for in-memory filehandles'
if !defined $content_length;
$headers{'Content-Length'} = $content_length;
# Wrap filehandle in a code ref for HTTP::Tiny streaming
my $chunk_size = 1024 * 64; # 64KB chunks
$body = sub {
my $buf;
my $n = read( $data, $buf, $chunk_size );
return $buf if $n;
return q{};
};
}
elsif ( ref $data eq 'SCALAR' ) {
# --- Scalar ref path ---
t/01-s3-lite.t view on Meta::CPAN
my $captured = {};
local *Amazon::S3::Lite::_request = mock_request(
status => 206,
content => 'hello',
headers => { 'content-type' => 'text/plain', 'content-length' => '5', 'etag' => '"abc"' },
capture => \$captured,
);
$s3->get_object( 'test-bucket', 'hello.txt', range => 'bytes=0-4' );
is $captured->{headers}{Range}, 'bytes=0-4', 'Range header set';
# filename â streaming to disk
{
my ( $fh, $fname ) = tempfile( UNLINK => 1 );
close $fh;
local *Amazon::S3::Lite::_request = sub {
my ( $self, $method, $url, $headers, $content, $extra ) = @_;
$extra->{data_callback}->('hello ') if $extra->{data_callback};
$extra->{data_callback}->('world') if $extra->{data_callback};
return {
status => 200,
( run in 2.442 seconds using v1.01-cache-2.11-cpan-cdf2f3d4e48 )