NAME
Asset::File - File Operation interface
SYNOPSIS
use
Asset::File;
# Temporary file
my
$file
= Asset::File->new;
$file
->add_chunk(
'foo bar baz'
);
say
'File contains "bar"'
if
$file
->contains(
'bar'
) >= 0;
say
$file
->slurp;
# Existing file
my
$file
= Asset::File->new(
path
=>
'/home/sri/foo.txt'
);
$file
->move_to(
'/yada.txt'
);
say
$file
->slurp;
DESCRIPTION
Asset::File is a file content interface.
ATTRIBUTES
cleanup
my
$bool
=
$file
->cleanup;
$file
=
$file
->cleanup(
$bool
);
Delete "path" automatically once the file is not used anymore.
handle
my
$handle
=
$file
->handle;
$file
=
$file
->handle(IO::File->new);
Filehandle, created on demand.
path
my
$path
=
$file
->path;
$file
=
$file
->path(
'/home/sri/foo.txt'
);
File path used to create "handle", can also be automatically generated if necessary.
METHODS
add_chunk
$file
=
$file
->add_chunk(
'foo bar baz'
);
Add chunk of data, if there is range from range position to start writing.
contains
my
$position
=
$file
->contains(
'bar'
);
Check if asset contains a specific string, if there is range from range position to start checking.
get_chunk
my
$bytes
=
$file
->get_chunk(
$offset
);
my
$bytes
=
$file
->get_chunk(
$offset
,
$max
);
Get chunk of data starting from a specific position, defaults to a maximum chunk size of 131072
bytes (128KB).
is_file
my
$true
=
$file
->is_file;
True.
move_to
$file
=
$file
->move_to(
'/home/sri/bar.txt'
);
Move asset data into a specific file and disable "cleanup".
mtime
my
$mtime
=
$file
->mtime;
Modification time of asset.
size
my
$size
=
$file
->size;
Size of asset data in bytes.
md5sum
my
$md5
=
$file
->md5sum;
return the md5 digest in hexadecimal form file;
sha1sum
my
$sha1
=
$file
->sha1sum;
return the sha1 digest in hexadecimal form file;
slurp
my
$bytes
=
$file
->slurp;
Read all asset data at once.