Pyjo.Asset.Memory - In-memory storage for HTTP content¶
import Pyjo.Asset.Memory
asset_mem = Pyjo.Asset.Memory.new()
asset_mem.add_chunk(b'foo bar baz')
print(asset_mem.slurp())
Pyjo.Asset.Memory
is an in-memory storage backend for HTTP content.
Events¶
Pyjo.Asset.Memory
inherits all events from Pyjo.Asset
and can emit
the following new ones.
upgrade¶
@content.on
def upgrade(asset_mem, asset_file):
...
Emitted when asset gets upgraded to a Pyjo.Asset.File
object.
@content.on
def upgrade(asset_mem, asset_file):
asset_file.tmpdir = '/tmp'
Classes¶
-
class
Pyjo.Asset.Memory.
Pyjo_Asset_Memory
(**kwargs)¶ Pyjo.Asset.Memory
inherits all attributes and methods fromPyjo.Asset
and implements the following new ones.-
add_chunk
(chunk='')¶ asset_mem = asset_mem.add_chunk(b'foo bar baz') asset_mem.auto_upgrade = True asset_file = asset_mem.add_chunk(b'abc' * 262144)
Add chunk of data and upgrade to
Pyjo.Asset.File
object if necessary.
-
auto_upgrade
= None¶ boolean = asset_mem.auto_upgrade asset_mem.auto_upgrade = boolean
Try to detect if content size exceeds
max_memory_size
limit and automatically upgrade to aPyjo.Asset.File
object.
-
close
()¶ asset_mem.close()
Close asset immediately and free resources.
-
contains
(chunk)¶ position = asset_mem.contains(b'bar')
Check if asset contains a specific string.
-
get_chunk
(offset, maximum=131072)¶ chunk = asset_mem.get_chunk(offset) chunk = asset_mem.get_chunk(offset, maximum)
Get chunk of data starting from a specific position, defaults to a maximum chunk size of
131072
bytes (128KB).
-
max_memory_size
= None¶ size = asset_mem.max_memory_size asset_mem.max_memory_size = 1024
Maximum size in bytes of data to keep in memory before automatically upgrading to a
Pyjo.Asset.File
object, defaults to the value of theMOJO_MAX_MEMORY_SIZE
environment variable or262144
(256KB).
-
move_to
(dst)¶ file = asset_mem.move_to('/home/pyjo/bar.txt')
Move asset data into a specific file.
-
mtime
= None¶ mtime = asset_mem.mtime asset_mem.mtime = 1408567500
Modification time of asset, defaults to the time this class was loaded.
-
size
¶ size = asset_mem.size
Size of asset data in bytes.
-
slurp
()¶ bstring = asset_mem.slurp()
Read all asset data at once.
-
-
Pyjo.Asset.Memory.
object
¶ alias of
Pyjo_Asset_Memory