Mila 0.13.48
Deep Neural Network Library
Loading...
Searching...
No Matches
Mila::Dnn::Serialization::ZipSerializer Class Referenceexport

ZIP archive serializer built on miniz. More...

Inheritance diagram for Mila::Dnn::Serialization::ZipSerializer:
Collaboration diagram for Mila::Dnn::Serialization::ZipSerializer:

Public Member Functions

 ZipSerializer () noexcept
 Construct an empty, closed ZipSerializer.
 ZipSerializer (const ZipSerializer &)=delete
 ZipSerializer (ZipSerializer &&other) noexcept
 ~ZipSerializer ()
 Destructor ensures underlying archive is closed.
bool addData (const std::string &path, const void *data, size_t size) override
 Add a binary blob to the archive at the given internal path.
bool addData (const std::string &path, std::span< const std::byte > data)
 Add a binary blob using std::span (C++23 style).
bool addMetadata (const std::string &key, const std::string &value) override
 Store small textual metadata under the "metadata/" prefix.
bool close () override
 Finalize and close the archive.
size_t extractData (const std::string &path, std::span< std::byte > buffer)
 Extract a file using std::span (C++23 style).
size_t extractData (const std::string &path, void *data, size_t size) override
 Extract a file from the archive into a caller-provided buffer.
const std::string & getFilename () const noexcept override
 Get the filename of the currently open archive.
size_t getFileSize (const std::string &path) const override
 Get the uncompressed size of the file stored at path.
std::string getMetadata (const std::string &key) const override
 Retrieve textual metadata previously stored with addMetadata().
bool hasFile (const std::string &path) const override
 Check whether the archive contains the given path.
bool isOpen () const noexcept override
 Check if the serializer is currently open.
bool isOpenForRead () const noexcept override
 Check if the serializer is open for reading.
bool isOpenForWrite () const noexcept override
 Check if the serializer is open for writing.
std::vector< std::string > listFiles () const override
 List all files contained in the open archive.
bool open (const std::string &filename, OpenMode mode) override
 Open an archive for read or write (create/overwrite).
ZipSerializeroperator= (const ZipSerializer &)=delete
ZipSerializeroperator= (ZipSerializer &&other) noexcept
Public Member Functions inherited from Mila::Dnn::Serialization::ArchiveSerializer
virtual ~ArchiveSerializer ()=default
Public Member Functions inherited from Mila::Dnn::Serialization::Serializer
virtual ~Serializer ()=default

Private Types

enum class  State { Closed , OpenForRead , OpenForWrite }
 Archive state enumeration. More...

Static Private Member Functions

static std::string normalizeZipPath (std::string_view raw)
 Normalize an archive-internal path to ZIP canonical form.

Private Attributes

std::string filename_
State state_ = State::Closed
mz_zip_archive zip_

Detailed Description

ZIP archive serializer built on miniz.

Responsibilities:

  • Write and read files (binary blobs and JSON) into a ZIP archive.
  • Provide simple metadata storage under the "metadata/" prefix.

Notes:

  • Instances are not thread-safe; callers must synchronize access.
  • Move-only type; copying is disabled to prevent resource conflicts.
  • Maintains explicit open/closed state for robustness.

Member Enumeration Documentation

◆ State

Archive state enumeration.

Enumerator
Closed 
OpenForRead 
OpenForWrite 

Constructor & Destructor Documentation

◆ ZipSerializer() [1/3]

Mila::Dnn::Serialization::ZipSerializer::ZipSerializer ( )
inlinenoexcept

Construct an empty, closed ZipSerializer.

The underlying miniz archive structure is zero-initialized.

Here is the caller graph for this function:

◆ ~ZipSerializer()

Mila::Dnn::Serialization::ZipSerializer::~ZipSerializer ( )
inline

Destructor ensures underlying archive is closed.

Best-effort cleanup is performed and exceptions are suppressed.

Here is the call graph for this function:

◆ ZipSerializer() [2/3]

Mila::Dnn::Serialization::ZipSerializer::ZipSerializer ( const ZipSerializer & )
delete
Here is the call graph for this function:

◆ ZipSerializer() [3/3]

Mila::Dnn::Serialization::ZipSerializer::ZipSerializer ( ZipSerializer && other)
inlinenoexcept
Here is the call graph for this function:

Member Function Documentation

◆ addData() [1/2]

bool Mila::Dnn::Serialization::ZipSerializer::addData ( const std::string & path,
const void * data,
size_t size )
inlinenodiscardoverridevirtual

Add a binary blob to the archive at the given internal path.

Paths are normalized to use forward slashes and stripped of leading './' or '/'.

Parameters
pathArchive-internal path (e.g., "network/weights.bin").
dataPointer to source bytes (may be null if size == 0).
sizeNumber of bytes to write.
Returns
true on success, false on failure.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ addData() [2/2]

bool Mila::Dnn::Serialization::ZipSerializer::addData ( const std::string & path,
std::span< const std::byte > data )
inlinenodiscard

Add a binary blob using std::span (C++23 style).

Parameters
pathArchive-internal path.
dataSpan of bytes to write.
Returns
true on success, false on failure.
Here is the call graph for this function:

◆ addMetadata()

bool Mila::Dnn::Serialization::ZipSerializer::addMetadata ( const std::string & key,
const std::string & value )
inlinenodiscardoverridevirtual

Store small textual metadata under the "metadata/" prefix.

Parameters
keyMetadata key (will be stored as "metadata/<key>").
valueMetadata value bytes.
Returns
true on success.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:

◆ close()

bool Mila::Dnn::Serialization::ZipSerializer::close ( )
inlinenodiscardoverridevirtual

Finalize and close the archive.

For write mode this ensures the archive is finalized and internal miniz state is released. For read mode releases reader resources.

Returns
true on success, false on internal miniz failure.

Implements Mila::Dnn::Serialization::Serializer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ extractData() [1/2]

size_t Mila::Dnn::Serialization::ZipSerializer::extractData ( const std::string & path,
std::span< std::byte > buffer )
inlinenodiscard

Extract a file using std::span (C++23 style).

Parameters
pathArchive-internal path to extract.
bufferSpan to receive file contents.
Returns
Number of bytes written into the buffer, or 0 on error.
Here is the call graph for this function:

◆ extractData() [2/2]

size_t Mila::Dnn::Serialization::ZipSerializer::extractData ( const std::string & path,
void * data,
size_t size )
inlinenodiscardoverridevirtual

Extract a file from the archive into a caller-provided buffer.

Parameters
pathArchive-internal path to extract.
dataPre-allocated buffer to receive file contents.
sizeSize of the provided buffer in bytes.
Returns
Number of bytes written into the buffer, or 0 on error.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFilename()

const std::string & Mila::Dnn::Serialization::ZipSerializer::getFilename ( ) const
inlinenodiscardoverridevirtualnoexcept

Get the filename of the currently open archive.

Returns
Filename, or empty string if no archive is open.

Implements Mila::Dnn::Serialization::Serializer.

◆ getFileSize()

size_t Mila::Dnn::Serialization::ZipSerializer::getFileSize ( const std::string & path) const
inlinenodiscardoverridevirtual

Get the uncompressed size of the file stored at path.

Parameters
pathArchive-internal path.
Returns
File size in bytes, or 0 if the file is missing or an error occurred.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ getMetadata()

std::string Mila::Dnn::Serialization::ZipSerializer::getMetadata ( const std::string & key) const
inlinenodiscardoverridevirtual

Retrieve textual metadata previously stored with addMetadata().

Parameters
keyMetadata key.
Returns
Metadata value string, or empty string if missing or on error.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:

◆ hasFile()

bool Mila::Dnn::Serialization::ZipSerializer::hasFile ( const std::string & path) const
inlinenodiscardoverridevirtual

Check whether the archive contains the given path.

Parameters
pathArchive-internal path to query.
Returns
true if the file exists and archive is open for read.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:

◆ isOpen()

bool Mila::Dnn::Serialization::ZipSerializer::isOpen ( ) const
inlinenodiscardoverridevirtualnoexcept

Check if the serializer is currently open.

Returns
true if open for reading or writing, false if closed.

Implements Mila::Dnn::Serialization::Serializer.

◆ isOpenForRead()

bool Mila::Dnn::Serialization::ZipSerializer::isOpenForRead ( ) const
inlinenodiscardoverridevirtualnoexcept

Check if the serializer is open for reading.

Returns
true if open for reading.

Implements Mila::Dnn::Serialization::Serializer.

Here is the caller graph for this function:

◆ isOpenForWrite()

bool Mila::Dnn::Serialization::ZipSerializer::isOpenForWrite ( ) const
inlinenodiscardoverridevirtualnoexcept

Check if the serializer is open for writing.

Returns
true if open for writing.

Implements Mila::Dnn::Serialization::Serializer.

Here is the caller graph for this function:

◆ listFiles()

std::vector< std::string > Mila::Dnn::Serialization::ZipSerializer::listFiles ( ) const
inlinenodiscardoverridevirtual

List all files contained in the open archive.

Returns
Vector of archive-internal file paths. Empty if archive is closed or opened for writing.

Implements Mila::Dnn::Serialization::ArchiveSerializer.

Here is the call graph for this function:

◆ normalizeZipPath()

std::string Mila::Dnn::Serialization::ZipSerializer::normalizeZipPath ( std::string_view raw)
inlinestaticprivate

Normalize an archive-internal path to ZIP canonical form.

Converts backslashes to forward slashes, collapses repeated slashes, and strips a leading "./" or leading '/' if present.

Parameters
rawRaw path provided by caller.
Returns
Normalized path suitable for use with miniz.
Here is the caller graph for this function:

◆ open()

bool Mila::Dnn::Serialization::ZipSerializer::open ( const std::string & filename,
OpenMode mode )
inlinenodiscardoverridevirtual

Open an archive for read or write (create/overwrite).

Combines previous openForRead/openForWrite into one API using ModelSerializer::OpenMode to select the behavior.

Parameters
filenameFilesystem path to open.
modeOpenMode::Read or OpenMode::Write.
Returns
true on success, false on failure.

Implements Mila::Dnn::Serialization::Serializer.

Here is the call graph for this function:

◆ operator=() [1/2]

ZipSerializer & Mila::Dnn::Serialization::ZipSerializer::operator= ( const ZipSerializer & )
delete
Here is the call graph for this function:

◆ operator=() [2/2]

ZipSerializer & Mila::Dnn::Serialization::ZipSerializer::operator= ( ZipSerializer && other)
inlinenoexcept
Here is the call graph for this function:

Member Data Documentation

◆ filename_

std::string Mila::Dnn::Serialization::ZipSerializer::filename_
private

◆ state_

State Mila::Dnn::Serialization::ZipSerializer::state_ = State::Closed
private

◆ zip_

mz_zip_archive Mila::Dnn::Serialization::ZipSerializer::zip_
mutableprivate

The documentation for this class was generated from the following file: