BlockFile

class BlockFile(data=<cfinterface.data.blockdata.BlockData object>)[source]

Class that models a file divided by blocks, where the reading and writing are given by a series of blocks.

property data: BlockData

Exposes the BlockData object, which gives access to the methods:

  • preppend()

  • append()

  • add_before()

  • add_after()

  • get_blocks_of_type()

Returns:

The data internal object

Return type:

BlockData

classmethod read(content: str | bytes, *args, **kwargs)[source]

Reads the blockfile data from either a given file or a buffer.

Parameters:

content (str | bytes) – The file name in disk or the file contents themselves

classmethod set_version(v: str)[source]

Sets the file’s version to be read. Different file versions may contain different blocks. The version to be set is considered is forced to the latest version with a new block set available.

If a BlockFile has VERSIONS with keys {“v0”: …, “v1”: …}, calling set_version("v2") will set the version to v1.

Parameters:

v (str) – The file version to be read.

write(to: str | IO, *args, **kwargs)[source]

Write the blockfile data to a given file or buffer.

Parameters:

to (str | IO) – The writing destination, being a string for writing to a file or the IO buffer