Name
SPVM::Mojo::Asset::File - File storage for HTTP content
Description
Mojo::Asset::File class in SPVM is a file storage backend for HTTP content.
Usage
use Mojo::Asset::File;
# Temporary file
my $file = Mojo::Asset::File->new;
$file->add_chunk("foo bar baz");
if ($file->contains("bar") >= 0) {
say "File contains \"bar\"" ;
}
say $file->slurp;
# Existing file
my $file = Mojo::Asset::File->new;
$file->set_path("/home/sri/foo.txt");
$file->move_to("/yada.txt");
say $file->slurp;
Fields
cleanup
has cleanup : rw byte;
Delete "path" automatically once the file is not used anymore.
path
has path : rw string;
Filehandle, created on demand for "path", which can be generated automatically and safely based on "tmpdir".
handle
has handle : rw IO::File;
File path used to create "handle".
tmpdir
has tmpdir : rw string;
Temporary directory used to generate "path", defaults to the value of the MOJO_TMPDIR
environment variable or auto-detection.
Class Methods
new
static method new : Mojo::Asset::File ();
Creates a new Mojo::Asset::File object, and returns it.
Instance Methods
add_chunk
method add_chunk : Mojo::Asset::File ($chunk : string);
Add chunk of data.
contains
method contains : int ($string : string);
Check if asset contains a specific string.
get_chunk
method get_chunk : string ($offset : long, $max : int = -1);
Get chunk of data starting from a specific position, defaults to a maximum chunk size of 131072
bytes (128KiB).
is_file
method is_file : int ();
True, this is a Mojo::Asset::File object.
move_to
method move_to : void ($file : string);
Move asset data into a specific file and disable "cleanup".
mtime
method mtime : long ();
Modification time of asset.
size
method size : long ();
Size of asset data in bytes.
slurp
method slurp : string ();
Read all asset data at once.
to_file
method to_file : Mojo::Asset::File ();
Does nothing but return the invocant, since we already have a Mojo::Asset::File object.
See Also
Copyright & License
Copyright (c) 2025 Yuki Kimoto
MIT License