bsa::fo4::chunk class final
#include <bsa/fo4.hpp>

Represents a chunk of a file within the FO4 virtual filesystem.

Base classes

class bsa::components::compressed_byte_container
A byte storage container with compression support.

Public types

struct mips_t
Unique to format::directx.

Public variables

struct bsa::fo4::chunk::mips_t mips

Capacity

auto empty() const -> bool noexcept
Checks if the underlying byte container is empty.
auto size() const -> std::size_t noexcept
Returns the size of the underlying byte container.

Compression

void compress(compression_level a_level = compression_level::normal)
Compresses the file.
auto compress_bound() const -> std::size_t
Returns an upper bound on the storage size required to compress the file.
auto compress_into(std::span<std::byte> a_out, compression_level a_level = compression_level::normal) const -> std::size_t
Compresses the file into the given buffer.

Decompression

void decompress()
Decompresses the file.
void decompress_into(std::span<std::byte> a_out) const
Decompresses the file into the given buffer.
auto decompressed_size() const -> std::size_t noexcept
Retrieves the decompressed size of the compressed storage.

Element access

auto as_bytes() const -> std::span<const std::byte> noexcept
Retrieves an immutable view into the underlying bytes.
auto data() const -> const std::byte* noexcept
Retrieves an immutable pointer to the underlying bytes.

Modifiers

void clear() noexcept
Clears the data and mips of the chunk.
void set_data(std::span<const std::byte> a_data, std::optional<std::size_t> a_decompressedSize = std::nullopt) noexcept
Assigns the underlying container to be a non-owning view into the given data.
void set_data(std::vector<std::byte> a_data, std::optional<std::size_t> a_decompressedSize = std::nullopt) noexcept
Assigns the underlying container to be an owning view into the given data.

Observers

auto compressed() const -> bool noexcept
Checks if the underlying bytes are compressed.

Function documentation

bool bsa::fo4::chunk::empty() const noexcept

Checks if the underlying byte container is empty.

std::size_t bsa::fo4::chunk::size() const noexcept

Returns the size of the underlying byte container.

void bsa::fo4::chunk::compress(compression_level a_level = compression_level::normal)

Compresses the file.

Parameters
a_level The level to compress the data at.
Exceptions
bsa::compression_error Thrown when any backend compression library errors are encountered.

std::size_t bsa::fo4::chunk::compress_bound() const

Returns an upper bound on the storage size required to compress the file.

Returns Returns the size required to successfully compress the file.
Exceptions
bsa::compression_error Thrown when any backend compression library errors are encountered.

std::size_t bsa::fo4::chunk::compress_into(std::span<std::byte> a_out, compression_level a_level = compression_level::normal) const

Compresses the file into the given buffer.

Parameters
a_out The buffer to compress the file into.
a_level The level to compress the data at.
Returns The final size of the compressed buffer.
Exceptions
bsa::compression_error Thrown when any backend compression library errors are encountered.

void bsa::fo4::chunk::decompress()

Decompresses the file.

Exceptions
bsa::compression_error Thrown when any backend compression library errors are encountered.

void bsa::fo4::chunk::decompress_into(std::span<std::byte> a_out) const

Decompresses the file into the given buffer.

Parameters
a_out The buffer to decompress the file into.
Exceptions
bsa::compression_error Thrown when any backend compression library errors are encountered.

std::size_t bsa::fo4::chunk::decompressed_size() const noexcept

Retrieves the decompressed size of the compressed storage.

Only valid if the container is compressed.

std::span<const std::byte> bsa::fo4::chunk::as_bytes() const noexcept

Retrieves an immutable view into the underlying bytes.

const std::byte* bsa::fo4::chunk::data() const noexcept

Retrieves an immutable pointer to the underlying bytes.

void bsa::fo4::chunk::set_data(std::span<const std::byte> a_data, std::optional<std::size_t> a_decompressedSize = std::nullopt) noexcept

Assigns the underlying container to be a non-owning view into the given data.

Parameters
a_data The data to store a view to.
a_decompressedSize The decompressed size of the data, if the given data is compressed.

void bsa::fo4::chunk::set_data(std::vector<std::byte> a_data, std::optional<std::size_t> a_decompressedSize = std::nullopt) noexcept

Assigns the underlying container to be an owning view into the given data.

Parameters
a_data The data to take ownership of.
a_decompressedSize The decompressed size of the data, if the given data is compressed.

bool bsa::fo4::chunk::compressed() const noexcept

Checks if the underlying bytes are compressed.