Open 3D Engine Archive Gem API Reference 23.10.0
O3DE is an open-source, fully-featured, high-fidelity, modular 3D engine for building games and simulations, available to every industry.
Archive::ArchiveWriter Class Reference

#include <ArchiveWriter.h>

Inherits Archive::IArchiveWriter.

Public Types

using CommitResult = AZStd::expected< void, ResultString >
 
- Public Types inherited from Archive::IArchiveWriter
using ArchiveStreamPtr = AZStd::unique_ptr< AZ::IO::GenericStream, ArchiveStreamDeleter >
 
using CommitResult = AZStd::expected< void, ResultString >
 

Public Member Functions

 AZ_TYPE_INFO_WITH_NAME_DECL (ArchiveWriter)
 
 AZ_RTTI_NO_TYPE_INFO_DECL ()
 
 ArchiveWriter (const ArchiveWriterSettings &writerSettings)
 Create an archive writer using the specified writer settings.
 
 ArchiveWriter (AZ::IO::PathView archivePath, const ArchiveWriterSettings &writerSettings={})
 
 ArchiveWriter (ArchiveStreamPtr archiveStream, const ArchiveWriterSettings &writerSettings={})
 Takes ownership of the open stream and will optionally delete it based on the ArchiveFileDeleter.
 
bool MountArchive (AZ::IO::PathView archivePath) override
 
bool MountArchive (ArchiveStreamPtr archiveStream) override
 
void UnmountArchive () override
 
bool IsMounted () const override
 Returns if an open archive that is mounted.
 
CommitResult Commit () override
 
ArchiveAddFileResult AddFileToArchive (AZ::IO::GenericStream &inputStream, const ArchiveWriterFileSettings &fileSettings) override
 
ArchiveAddFileResult AddFileToArchive (AZStd::span< const AZStd::byte > inputSpan, const ArchiveWriterFileSettings &fileSettings) override
 
ArchiveFileToken FindFile (AZ::IO::PathView relativePath) const override
 
bool ContainsFile (AZ::IO::PathView relativePath) const override
 
ArchiveRemoveFileResult RemoveFileFromArchive (ArchiveFileToken filePathToken) override
 
ArchiveRemoveFileResult RemoveFileFromArchive (AZ::IO::PathView relativePath) override
 
bool DumpArchiveMetadata (AZ::IO::GenericStream &metadataStream, const ArchiveMetadataSettings &metadataSettings={}) const override
 
- Public Member Functions inherited from Archive::IArchiveWriter
 AZ_TYPE_INFO_WITH_NAME_DECL (IArchiveWriter)
 
 AZ_RTTI_NO_TYPE_INFO_DECL ()
 
virtual bool MountArchive (AZ::IO::PathView archivePath)=0
 
virtual bool MountArchive (ArchiveStreamPtr archiveStream)=0
 
virtual void UnmountArchive ()=0
 
virtual bool IsMounted () const =0
 Returns if an open archive that is mounted.
 
virtual CommitResult Commit ()=0
 
virtual ArchiveAddFileResult AddFileToArchive (AZ::IO::GenericStream &inputStream, const ArchiveWriterFileSettings &fileSettings)=0
 
virtual ArchiveAddFileResult AddFileToArchive (AZStd::span< const AZStd::byte > inputSpan, const ArchiveWriterFileSettings &fileSettings)=0
 
virtual ArchiveFileToken FindFile (AZ::IO::PathView relativePath) const =0
 
virtual bool ContainsFile (AZ::IO::PathView relativePath) const =0
 
virtual ArchiveRemoveFileResult RemoveFileFromArchive (ArchiveFileToken filePathToken)=0
 
virtual ArchiveRemoveFileResult RemoveFileFromArchive (AZ::IO::PathView relativePath)=0
 
virtual bool DumpArchiveMetadata (AZ::IO::GenericStream &metadataStream, const ArchiveMetadataSettings &metadataSettings={}) const =0
 

Public Attributes

 AZ_CLASS_ALLOCATOR_DECL
 
- Public Attributes inherited from Archive::IArchiveWriter
 AZ_CLASS_ALLOCATOR_DECL
 

Detailed Description

class which is used to write into a stream the O3DE Archive format The caller is required to supply a ArchiveWriterSettings structure which contains the ArchiveHeader and ArchiveTableOfContents data to use when writing to the Archive file The class can be initialized with a user supplied AZ::IO::GenericStream class in which case it should be open in stream should needs to be open with OpenMode::ModeUpdate The reason why is that to locate information about any content files in order to update an existing archive it read access is needed The recommend OpenMode value for opening a new archive or updating an existing archive are as follows constexpr OpenMode mode = OpenMode::Update | OpenMode::Append | OpenMode::Binary The Append option makes sure that the Archive is not truncated on open

Member Typedef Documentation

◆ CommitResult

using Archive::ArchiveWriter::CommitResult = AZStd::expected<void, ResultString>

Write the updated ArchiveHeader to the beginning of the stream and Table of Contents to end of the stream

If this call is successful, the archive TOC has been successfully written This function has been marked [[nodiscard]], to ensure the caller checks the return value

Returns
A successful expectation if the TOC has been written

Constructor & Destructor Documentation

◆ ArchiveWriter()

Archive::ArchiveWriter::ArchiveWriter ( AZ::IO::PathView  archivePath,
const ArchiveWriterSettings writerSettings = {} 
)
explicit

Open an file at the specified file path and takes sole ownership of it The ArchiveWriter will close the file on Unmount

Member Function Documentation

◆ AddFileToArchive() [1/2]

ArchiveAddFileResult Archive::ArchiveWriter::AddFileToArchive ( AZ::IO::GenericStream &  inputStream,
const ArchiveWriterFileSettings fileSettings 
)
overridevirtual

Adds the content from the stream to the relative path

Parameters
inputStreamstream class where data for the file is source from The entire stream is read into the memory and written into archive
fileSettingssettings used to configure the relative path to write to the archive for the given file data. It also allows users to configure the compression algorithm to use, and whether the AddFileToArchive logic fails if an existing file is being added
Returns
ArchiveAddFileResult containing the actual compression file path as saved to the Archive TOC, the compression algorithm used and an Archive File Token which can be used to remove the file if need be On failure, the result outcome contains any errors that have occurred

Implements Archive::IArchiveWriter.

◆ AddFileToArchive() [2/2]

ArchiveAddFileResult Archive::ArchiveWriter::AddFileToArchive ( AZStd::span< const AZStd::byte >  inputSpan,
const ArchiveWriterFileSettings fileSettings 
)
overridevirtual

Use the span contents to add the file to the archive

Parameters
inputSpanview of data which will be written to the archive at the relative path supplied in the @fileSettings parameter
fileSettingssettings used to configure the relative path to write to the archive for the given file data. It also allows users to configure the compression algorithm to use, and whether the AddFileToArchive logic fails if an existing file is being added
Returns
ArchiveAddFileResult containing the actual compression file path as saved to the Archive TOC, the compression algorithm used and an Archive File Token which can be used to remove the file if need be On failure, the result outcome contains any errors that have occurred

Implements Archive::IArchiveWriter.

◆ Commit()

CommitResult Archive::ArchiveWriter::Commit ( )
overridevirtual

◆ ContainsFile()

bool Archive::ArchiveWriter::ContainsFile ( AZ::IO::PathView  relativePath) const
overridevirtual

Returns if the archive contains a relative path

Parameters
relativePathRelative path within archive to search for
Returns
true if the relative path is contained with the Archive equivalent to return FindFile(relativePath) != InvalidArchiveFileToken;

Implements Archive::IArchiveWriter.

◆ DumpArchiveMetadata()

bool Archive::ArchiveWriter::DumpArchiveMetadata ( AZ::IO::GenericStream &  metadataStream,
const ArchiveMetadataSettings metadataSettings = {} 
) const
overridevirtual

Dump metadata for the archive to the supplied generic stream

Parameters
metadataStreamarchive file metadata will be written to the stream
metadataSettingssettings using which control the file metadata to write to the stream
Returns
true if metadata was successfully written

Implements Archive::IArchiveWriter.

◆ FindFile()

ArchiveFileToken Archive::ArchiveWriter::FindFile ( AZ::IO::PathView  relativePath) const
overridevirtual

Searches for a relative path within the archive

Parameters
relativePathRelative path within archive to search for
Returns
A token that identifies the Archive file if it exist if the with the specified path doesn't exist InvalidArchiveFileToken is returned

Implements Archive::IArchiveWriter.

◆ IsMounted()

bool Archive::ArchiveWriter::IsMounted ( ) const
overridevirtual

Returns if an open archive that is mounted.

Implements Archive::IArchiveWriter.

◆ MountArchive() [1/2]

bool Archive::ArchiveWriter::MountArchive ( ArchiveStreamPtr  archiveStream)
overridevirtual

◆ MountArchive() [2/2]

bool Archive::ArchiveWriter::MountArchive ( AZ::IO::PathView  archivePath)
overridevirtual

Opens the archive path and returns true if successful Will unmount any previously mounted archive

Implements Archive::IArchiveWriter.

◆ RemoveFileFromArchive() [1/2]

ArchiveRemoveFileResult Archive::ArchiveWriter::RemoveFileFromArchive ( ArchiveFileToken  filePathToken)
overridevirtual

Removes the file from the archive using the ArchiveFileToken

Parameters
filePathTokenIdentifier queried using FindFile or AddFileToArchive NOTE: The entry in the table of contents is not actually removed The index where the file is located using the filePathToken is just added to the removed file indices set
Returns
ArchiveRemoveResult with metadata about how the deleted file was stored in the Archive

Implements Archive::IArchiveWriter.

◆ RemoveFileFromArchive() [2/2]

ArchiveRemoveFileResult Archive::ArchiveWriter::RemoveFileFromArchive ( AZ::IO::PathView  relativePath)
overridevirtual

Removes the file from the archive using a relative path name

Parameters
relativePathrelative path within archive to search for
Returns
ArchiveRemoveResult with metadata about how the deleted file was stored in the Archive

Implements Archive::IArchiveWriter.

◆ UnmountArchive()

void Archive::ArchiveWriter::UnmountArchive ( )
overridevirtual

Closes the handle to the mounted archive stream This will invoke the Commit() function to write the archive TOC to the stream before closing the stream

Implements Archive::IArchiveWriter.


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