Pyjo.Asset.File - File storage for HTTP content¶
import Pyjo.Asset.File
# Temporary file
with Pyjo.Asset.File.new() as asset_file:
asset_file.add_chunk(b'foo bar baz')
if asset_file.contains(b'bar'):
print('File contains "bar"')
print(asset_file.slurp())
# Existing file
asset_file = Pyjo.Asset.File.new(path='/home/pyjo/foo.txt')
asset_file.move_to('/tmp/yada.txt')
print(asset_file.slurp())
Pyjo.Asset.File
is an file storage backend for HTTP content.
Events¶
Pyjo.Asset.File
inherits all events from Pyjo.Asset
.
Classes¶
-
class
Pyjo.Asset.File.
Pyjo_Asset_File
(**kwargs)¶ Pyjo.Asset.File
inherits all attributes and methods fromPyjo.Asset
and implements the following new ones.-
add_chunk
(chunk='')¶ asset_file = asset_file.add_chunk(b'foo bar baz')
Add chunk of data.
-
cleanup
= None¶ boolean = asset_file.cleanup asset_file.cleanup = boolean
Delete
path
automatically once the file is not used anymore.
-
close
()¶ asset_file.close()
Close asset immediately and free resources.
-
contains
(bstring)¶ position = asset_file.contains(b'bar')
Check if asset contains a specific string.
-
get_chunk
(offset, maximum=131072)¶ bstream = asset.get_chunk(offset) bstream = asset.get_chunk(offset, maximum)
Get chunk of data starting from a specific position, defaults to a maximum chunk size of
131072
bytes (128KB).
-
handle
¶ handle = asset_file.handle asset_file.handle = open('/home/pyjo/foo.txt', 'rb')
Filehandle, created on demand.
-
is_file
¶ true = asset_file.is_file
True.
-
move_to
(dst)¶ asset_file = asset_file.move_to('/home/pyjo/bar.txt')
Move asset data into a specific file and disable
cleanup
.
-
mtime
¶ mtime = asset_file.mtime
Modification time of asset.
-
path
= None¶ path = asset_file.path asset_file.path = '/home/pyjo/foo.txt'
File path used to create
handle
, can also be automatically generated if necessary.
-
size
¶ size = asset_file.size
Size of asset data in bytes. Reading the size flushes writing buffer.
-
slurp
()¶ bstring = asset_file.slurp()
Read all asset data at once.
-
-
Pyjo.Asset.File.
object
¶ alias of
Pyjo_Asset_File