NAME

Mojo::Asset::File - File asset

SYNOPSIS

use Mojo::Asset::File;

my $file = Mojo::Asset::File->new;
$file->add_chunk('foo bar baz');
say $file->slurp;

my $file = Mojo::Asset::File->new(path => '/foo/bar/baz.txt');
say $file->slurp;

DESCRIPTION

Mojo::Asset::File is a container for file assets.

ATTRIBUTES

Mojo::Asset::File inherits all attributes from Mojo::Asset and implements the following new ones.

cleanup

my $cleanup = $file->cleanup;
$file       = $file->cleanup(1);

Delete file automatically once it's not used anymore.

handle

my $handle = $file->handle;
$file      = $file->handle(IO::File->new);

Actual file handle.

path

my $path = $file->path;
$file    = $file->path('/foo/bar/baz.txt');

Actual file path.

tmpdir

my $tmpdir = $file->tmpdir;
$file      = $file->tmpdir('/tmp');

Temporary directory.

METHODS

Mojo::Asset::File inherits all methods from Mojo::Asset and implements the following new ones.

add_chunk

$file = $file->add_chunk('foo bar baz');

Add chunk of data.

contains

my $position = $file->contains('bar');

Check if asset contains a specific string.

get_chunk

my $chunk = $file->get_chunk($start);

Get chunk of data starting from a specific position.

is_file

my $true = $file->is_file;

True. Note that this method is EXPERIMENTAL and might change without warning!

move_to

$file = $file->move_to('/foo/bar/baz.txt');

Move asset data into a specific file.

size

my $size = $file->size;

Size of asset data in bytes.

slurp

my $string = $file->slurp;

Read all asset data at once.

SEE ALSO

Mojolicious, Mojolicious::Guides, http://mojolicio.us.