Class DataBasePackedFile
- Namespace
- LlamaLogic.Packages
- Assembly
- LlamaLogic.Packages.dll
Represents a Maxis DBPF format package file (🔒)
public sealed class DataBasePackedFile : IAsyncDisposable, IDisposable
- Inheritance
-
DataBasePackedFile
- Implements
- Inherited Members
Remarks
Streams and Disposal
When a package is opened by this class from a Stream, the class assumes ownership of the Stream. Manipulating the Stream afterward may result in undefined behavior. The class will dispose of the Stream when it is, itself, disposed.
To use the Save(bool, ResourceKeyOrder) or SaveAsync(bool, ResourceKeyOrder, CancellationToken) methods, the package must have been opened from a Stream which is writeable. This can also be determined by the caller in advance of attempting to use them by checking the value of the CanSaveInPlace property. However, for ease of use in web frameworks like ASP.NET Core, the CopyTo(Stream, ResourceKeyOrder) and CopyToAsync(Stream, ResourceKeyOrder, CancellationToken) methods do not require that the Stream which they are passed is seekable.
Lazy Loading
When a package is first opened using this class, the package index is read but the content of the package resources is not. All of the retrieval methods of this class have async counterparts for callers who prefer not to be blocked by I/O operations which may be required when retrieving resource content.
Because resource names (when applicable) are determined by their content, this class will not index resource names until they are first referenced, either explicitly by calling GetNames() or GetNamesAsync(CancellationToken), or implicitly by calling any of the other methods which deal with resource names. Afterward, the names are cached for the lifetime of the package instance and updated as the caller sets the content of resources or deletes them.
Thread Safety
All properties and methods of this class, including async methods, are kept thread-safe with internally managed locks. Async methods which accept cancellation tokens will honor signals so long as they have not progressed to mutating the state of the package.
Compression
Decompression of resource content is handled automatically by this class.
When retrieving resource content, this class will automatically decompress it using either proprietary Maxis internal or streaming compression, or ZLib compression. When saving resources, this class will always use ZLib compression. For more details, see the remarks for the CompressionMode enumeration.
Resource content is compressed in memory when it is set to minimize the amount of memory used while operating on a package.
Deleted Entries
This class honors the deleted entry flag in the package index under normal circumstances.
If a caller attempts to retrieve the content of a resource flagged as deleted, the class will throw a FileNotFoundException by default.
All retrieval methods have an optional force
bool parameter which, when true, will cause the class to attempt to retrieve the content of a resource flagged as deleted (this is not guaranteed to work).
Constructors
DataBasePackedFile()
Initializes a new, blank DataBasePackedFile
public DataBasePackedFile()
DataBasePackedFile(Stream)
Initializes a DataBasePackedFile from the specified stream
(🗑️💤)
public DataBasePackedFile(Stream stream)
Parameters
stream
Stream
DataBasePackedFile(string, bool)
Initializes a DataBasePackedFile from the specified path
(🗑️💤)
public DataBasePackedFile(string path, bool forReadOnly = true)
Parameters
Properties
CanSaveInPlace
Gets whether the package can be saved in place
public bool CanSaveInPlace { get; }
Property Value
Count
Gets the number of resources
public int Count { get; }
Property Value
CreationTime
Gets/sets when the package was created
public DateTimeOffset CreationTime { get; set; }
Property Value
FileVersion
Gets/sets the version of the format of the file
public Version FileVersion { get; set; }
Property Value
Remarks
This class is intended to work with versions of the Maxis DBPF format up to version 2.1
and going back as far as possible.
While it will permit the caller to specify any version they like, it does not guard against potential negative consequences which may result from such packages actually being used.
The default version for newly created packages is currently 2.1
.
this[ResourceKey]
Gets/sets the content of a resource with the specified key
public object? this[ResourceKey key] { get; set; }
Parameters
key
ResourceKey
Property Value
Keys
Gets a list of keys for all the resources in the package
public IReadOnlyList<ResourceKey> Keys { get; }
Property Value
UpdatedTime
Gets/sets when the package was last updated
public DateTimeOffset UpdatedTime { get; set; }
Property Value
UserVersion
Gets/sets the version of the user (presumably the user agent, actually? -- is Maxis versioning human beings?)
public Version UserVersion { get; set; }
Property Value
Methods
ContainsKey(ResourceKey)
Gets whether the package contains a resource with the specified key
public bool ContainsKey(ResourceKey key)
Parameters
key
ResourceKey
Returns
ContainsKeyAsync(ResourceKey, CancellationToken)
Gets whether the package contains a resource with the specified key
asynchronously
public Task<bool> ContainsKeyAsync(ResourceKey key, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeycancellationToken
CancellationToken
Returns
CopyTo(Stream, ResourceKeyOrder)
Copies the package in binary format to the specified destination
(🔄️🏃)
public void CopyTo(Stream destination, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
destination
StreamresourceKeyOrder
ResourceKeyOrder
Exceptions
- ArgumentNullException
destination
is null- ArgumentException
destination
is not writeable
CopyToAsync(Stream, ResourceKeyOrder, CancellationToken)
Copies the package in binary format to the specified destination
asynchronously (🔄️🏃)
public Task CopyToAsync(Stream destination, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
destination
StreamresourceKeyOrder
ResourceKeyOrdercancellationToken
CancellationToken
Returns
Exceptions
- ArgumentNullException
destination
is null- ArgumentException
destination
is not writeable
Delete(ResourceKey)
public bool Delete(ResourceKey key)
Parameters
key
ResourceKey
Returns
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public void Dispose()
DisposeAsync()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources asynchronously.
public ValueTask DisposeAsync()
Returns
- ValueTask
A task that represents the asynchronous dispose operation.
~DataBasePackedFile()
Called by the finalizer
protected ~DataBasePackedFile()
ForEach(ResourceKeyOrder, Predicate<ResourceKey>, Action<ResourceKey, ReadOnlyMemory<byte>>, CancellationToken)
Processes undeleted resources in the specified keyOrder
if they satisfy the specified keyPredicate
using the specified processResourceAction
public void ForEach(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Action<ResourceKey, ReadOnlyMemory<byte>> processResourceAction, CancellationToken cancellationToken = default)
Parameters
keyOrder
ResourceKeyOrderkeyPredicate
Predicate<ResourceKey>processResourceAction
Action<ResourceKey, ReadOnlyMemory<byte>>cancellationToken
CancellationToken
ForEachAsync(ResourceKeyOrder, Predicate<ResourceKey>, Func<ResourceKey, ReadOnlyMemory<byte>, Task>, CancellationToken)
Processes undeleted resources in the specified keyOrder
if they satisfy the specified keyPredicate
using the specified processResourceAsyncAction
public Task ForEachAsync(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Func<ResourceKey, ReadOnlyMemory<byte>, Task> processResourceAsyncAction, CancellationToken cancellationToken = default)
Parameters
keyOrder
ResourceKeyOrderkeyPredicate
Predicate<ResourceKey>processResourceAsyncAction
Func<ResourceKey, ReadOnlyMemory<byte>, Task>cancellationToken
CancellationToken
Returns
ForEachRaw(ResourceKeyOrder, Predicate<ResourceKey>, Action<ResourceKey, ReadOnlyMemory<byte>>, CancellationToken)
Processes undeleted raw resources (meaning that the library will not decompress a resource for you if it is compressed) in the specified keyOrder
if they satisfy the specified keyPredicate
using the specified processResourceAction
public void ForEachRaw(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Action<ResourceKey, ReadOnlyMemory<byte>> processResourceAction, CancellationToken cancellationToken = default)
Parameters
keyOrder
ResourceKeyOrderkeyPredicate
Predicate<ResourceKey>processResourceAction
Action<ResourceKey, ReadOnlyMemory<byte>>cancellationToken
CancellationToken
ForEachRawAsync(ResourceKeyOrder, Predicate<ResourceKey>, Func<ResourceKey, ReadOnlyMemory<byte>, Task>, CancellationToken)
Processes undeleted raw resources (meaning that the library will not decompress a resource for you if it is compressed) in the specified keyOrder
if they satisfy the specified keyPredicate
using the specified processResourceAsyncAction
public Task ForEachRawAsync(ResourceKeyOrder keyOrder, Predicate<ResourceKey> keyPredicate, Func<ResourceKey, ReadOnlyMemory<byte>, Task> processResourceAsyncAction, CancellationToken cancellationToken = default)
Parameters
keyOrder
ResourceKeyOrderkeyPredicate
Predicate<ResourceKey>processResourceAsyncAction
Func<ResourceKey, ReadOnlyMemory<byte>, Task>cancellationToken
CancellationToken
Returns
FromPathAsync(string, bool)
Initializes a DataBasePackedFile asynchronously from the specified path
(🗑️💤)
public static Task<DataBasePackedFile> FromPathAsync(string path, bool forReadOnly = true)
Parameters
Returns
FromStreamAsync(Stream, CancellationToken)
Initializes a DataBasePackedFile asynchronously from the specified stream
(🗑️💤)
public static Task<DataBasePackedFile> FromStreamAsync(Stream stream, CancellationToken cancellationToken = default)
Parameters
stream
StreamcancellationToken
CancellationToken
Returns
Get(ResourceKey, bool)
Gets the content of a resource with the specified key
public ReadOnlyMemory<byte> Get(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetAllSizes(Predicate<ResourceKey>?)
Gets the size of the content of each resource in the package indexed by key
public IReadOnlyDictionary<ResourceKey, int> GetAllSizes(Predicate<ResourceKey>? predicate = null)
Parameters
predicate
Predicate<ResourceKey>An optional predicate to filter the keys
Returns
GetAllSizesAsync(Predicate<ResourceKey>?, CancellationToken)
Gets the size of the content of each resource in the package indexed by key, asynchronously
public Task<IReadOnlyDictionary<ResourceKey, int>> GetAllSizesAsync(Predicate<ResourceKey>? predicate = null, CancellationToken cancellationToken = default)
Parameters
predicate
Predicate<ResourceKey>An optional predicate to filter the keys
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
GetAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
asynchronously
public Task<ReadOnlyMemory<byte>> GetAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
GetCount()
Gets the number of resources
public int GetCount()
Returns
GetCountAsync(CancellationToken)
Gets the number of resources asychronously
public Task<int> GetCountAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
GetData(ResourceKey, bool)
Gets the content of a resource with the specified key
as a DataModel
public DataModel GetData(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyforce
bool
Returns
GetDataAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
as a DataModel asynchronously
public Task<DataModel> GetDataAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyforce
boolcancellationToken
CancellationToken
Returns
GetExplicitCompressionMode(ResourceKey)
Gets the CompressionMode value to pass to Set methods to ensure they will compress the content of the resource specified by key
in the same way it is currently compressed in the package
public CompressionMode GetExplicitCompressionMode(ResourceKey key)
Parameters
key
ResourceKey
Returns
GetKeys(ResourceKeyOrder)
Gets a list of keys for all the resources in the package
public IReadOnlyList<ResourceKey> GetKeys(ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
resourceKeyOrder
ResourceKeyOrder
Returns
GetKeysAsync(ResourceKeyOrder, CancellationToken)
Gets a list of keys for all the resources in the package asynchronously
public Task<IReadOnlyList<ResourceKey>> GetKeysAsync(ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
resourceKeyOrder
ResourceKeyOrdercancellationToken
CancellationToken
Returns
GetKeysByName(string)
Gets a list of keys for resources with the specified name
public IReadOnlyList<ResourceKey> GetKeysByName(string name)
Parameters
name
string
Returns
GetKeysByNameAsync(string, CancellationToken)
Gets a list of keys for resources with the specified name
asynchronously
public Task<IReadOnlyList<ResourceKey>> GetKeysByNameAsync(string name, CancellationToken cancellationToken = default)
Parameters
name
stringcancellationToken
CancellationToken
Returns
GetModFileManifest(ResourceKey, bool)
Gets the content of a resource with the specified key
as a ModFileManifestModel
public ModFileManifestModel GetModFileManifest(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyforce
bool
Returns
GetModFileManifestAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
as a ModFileManifestModel asynchronously
public Task<ModFileManifestModel> GetModFileManifestAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyforce
boolcancellationToken
CancellationToken
Returns
GetModelAsync<TModel>(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
as a TModel
asynchronously
public Task<TModel> GetModelAsync<TModel>(ResourceKey key, bool force = false, CancellationToken cancellationToken = default) where TModel : IModel<TModel>
Parameters
key
ResourceKeyforce
boolcancellationToken
CancellationToken
Returns
- Task<TModel>
Type Parameters
TModel
A model used to browse and modify certain types of resources
Exceptions
- ArgumentException
TModel
cannot deal with resources of the type specified bykey
GetModel<TModel>(ResourceKey, bool)
Gets the content of a resource with the specified key
as a TModel
public TModel GetModel<TModel>(ResourceKey key, bool force = false) where TModel : IModel<TModel>
Parameters
key
ResourceKeyforce
bool
Returns
- TModel
Type Parameters
TModel
A model used to browse and modify certain types of resources
Exceptions
- ArgumentException
TModel
cannot deal with resources of the type specified bykey
GetNameByKey(ResourceKey)
Gets the name for the resource with the specified key
public string? GetNameByKey(ResourceKey key)
Parameters
key
ResourceKey
Returns
GetNameByKeyAsync(ResourceKey, CancellationToken)
Gets the name for the resource with the specified key
asynchronously
public Task<string?> GetNameByKeyAsync(ResourceKey key, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeycancellationToken
CancellationToken
Returns
GetNames()
Gets the names for all the resources in the package
public IReadOnlyList<string> GetNames()
Returns
GetNamesAsync(CancellationToken)
Gets the names for all the resources in the package asynchronously
public Task<IReadOnlyList<string>> GetNamesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
GetRaw(ResourceKey, bool)
Gets the raw content of a resource with the specified key
, meaning that the library will not decompress it for you if it is compressed
public ReadOnlyMemory<byte> GetRaw(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetRawAsync(ResourceKey, bool, CancellationToken)
Gets the raw content of a resource with the specified key
asynchronously, meaning that the library will not decompress it for you if it is compressed
public Task<ReadOnlyMemory<byte>> GetRawAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
GetSize(ResourceKey)
Gets the size of the content of the resource with the specified key
public int GetSize(ResourceKey key)
Parameters
key
ResourceKey
Returns
GetSizeAsync(ResourceKey, CancellationToken)
Gets the size of the content of the resource with the specified key
asynchronously
public Task<int> GetSizeAsync(ResourceKey key, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeycancellationToken
CancellationToken
Returns
GetStringTable(ResourceKey, bool)
Gets the content of a resource with the specified key
as a StringTableModel
public StringTableModel GetStringTable(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyforce
bool
Returns
GetStringTableAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
as a StringTableModel asynchronously
public Task<StringTableModel> GetStringTableAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyforce
boolcancellationToken
CancellationToken
Returns
GetText(ResourceKey, bool)
Gets the content of a resource with the specified key
as a string
public string GetText(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetTextAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
as a string asynchronously
public Task<string> GetTextAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
GetTranslucentJpegAsPng(ResourceKey, bool)
Gets the content of a resource that is a TS4 proprietary translucent JPEG based with the specified key
, reintegrated into RGBA and encoded as a PNG
public ReadOnlyMemory<byte> GetTranslucentJpegAsPng(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyforce
bool
Returns
GetTranslucentJpegAsPngAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource that is a TS4 proprietary translucent JPEG based with the specified key
, reintegrated into RGBA and encoded as a PNG, asynchronously
public Task<ReadOnlyMemory<byte>> GetTranslucentJpegAsPngAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyforce
boolcancellationToken
CancellationToken
Returns
GetXml(ResourceKey, bool)
Gets the content of a resource with the specified key
as an XDocument
public XDocument GetXml(ResourceKey key, bool force = false)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
Returns
GetXmlAsync(ResourceKey, bool, CancellationToken)
Gets the content of a resource with the specified key
as an XDocument asynchronously
public Task<XDocument> GetXmlAsync(ResourceKey key, bool force = false, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
force
booltrue to get the content of the resource even if it has been marked as deleted; otheriwse, false (default)
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
InternalCompress(ReadOnlyMemory<byte>, out bool)
Compresses the specified memory
in the manner of Maxis' internal algorithm, returning the result
public static ReadOnlyMemory<byte> InternalCompress(ReadOnlyMemory<byte> memory, out bool wasCompressed)
Parameters
memory
ReadOnlyMemory<byte>wasCompressed
bool
Returns
InternalDecompress(ReadOnlyMemory<byte>)
Decompresses the specified memory
in the manner of Maxis' internal algorithm, returning the result
public static ReadOnlyMemory<byte> InternalDecompress(ReadOnlyMemory<byte> memory)
Parameters
memory
ReadOnlyMemory<byte>
Returns
LoadAll(bool, CompressionMode)
Loads all resources in the package into memory
public void LoadAll(bool force = false, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
force
booltrue to get the content of the resources even if they has been marked as deleted; otheriwse, false (default)
compressionMode
CompressionModeThis parameter is now ignored
LoadAllAsync(bool, CompressionMode, CancellationToken)
Loads all resources in the package into memory
public Task LoadAllAsync(bool force = false, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
force
booltrue to get the content of the resources even if they has been marked as deleted; otheriwse, false (default)
compressionMode
CompressionModeThis parameter is now ignored
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
LoadNames()
Loads the names of all the resources in the package (a no-op if the names are already loaded)
public void LoadNames()
LoadNamesAsync(CancellationToken)
Loads the names of all the resources in the package asynchronously (a no-op if the names are already loaded)
public Task LoadNamesAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationToken
Returns
Save(bool, ResourceKeyOrder)
Saves the package to the stream from which it was loaded
public void Save(bool unloadFromMemory = false, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
unloadFromMemory
boolresourceKeyOrder
ResourceKeyOrder
Exceptions
- InvalidOperationException
The package was not loaded from stream or the stream is not writeable
SaveAs(string, ResourceKeyOrder)
Saves the package to the specified path
(🔄️🏃)
public void SaveAs(string path, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve)
Parameters
path
stringresourceKeyOrder
ResourceKeyOrder
SaveAsAsync(string, ResourceKeyOrder, CancellationToken)
Saves the package to the specified path
asynchronously (🔄️🏃)
public Task SaveAsAsync(string path, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
path
stringresourceKeyOrder
ResourceKeyOrdercancellationToken
CancellationToken
Returns
SaveAsync(bool, ResourceKeyOrder, CancellationToken)
Saves the package to the stream from which it was loaded asynchronously
public Task SaveAsync(bool unloadFromMemory = false, ResourceKeyOrder resourceKeyOrder = ResourceKeyOrder.Preserve, CancellationToken cancellationToken = default)
Parameters
unloadFromMemory
boolresourceKeyOrder
ResourceKeyOrdercancellationToken
CancellationToken
Returns
Exceptions
- InvalidOperationException
The package was not loaded from stream or the stream is not writeable
Set(ResourceKey, IModel, CompressionMode)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, IModel content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
key
ResourceKeyThe key of the resource
content
IModelThe content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
Returns
Set(ResourceKey, ReadOnlyMemory<byte>, CompressionMode)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, ReadOnlyMemory<byte> content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
key
ResourceKeyThe key of the resource
content
ReadOnlyMemory<byte>The content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
Returns
Set(ResourceKey, string, CompressionMode)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, string content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
key
ResourceKeyThe key of the resource
content
stringThe content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
Returns
Set(ResourceKey, XDocument, CompressionMode)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public bool Set(ResourceKey key, XDocument content, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
key
ResourceKeyThe key of the resource
content
XDocumentThe content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
Returns
SetAsync(ResourceKey, IModel, CompressionMode, CancellationToken)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, IModel content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
content
IModelThe content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
SetAsync(ResourceKey, ReadOnlyMemory<byte>, CompressionMode, CancellationToken)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, ReadOnlyMemory<byte> content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
content
ReadOnlyMemory<byte>The content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
SetAsync(ResourceKey, string, CompressionMode, CancellationToken)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, string content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
content
stringThe content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
SetAsync(ResourceKey, XDocument, CompressionMode, CancellationToken)
Sets the content
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public Task<bool> SetAsync(ResourceKey key, XDocument content, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
content
XDocumentThe content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
SetPngAsTranslucentJpegAsync(ResourceKey, ReadOnlyMemory<byte>, CancellationToken)
Sets the content of a resource as a TS4 proprietary translucent JPEG based on an RGBA image encoded as pngData
(the resource content will not be DBPF-compressed as it will already be JPEG lossy compressed and PNG DEFLATE compressed)
public Task SetPngAsTranslucentJpegAsync(ResourceKey key, ReadOnlyMemory<byte> pngData, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
pngData
ReadOnlyMemory<byte>The encoded PNG data
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
SetXml(ResourceKey, string, CompressionMode)
Sets the xmlContent
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public bool SetXml(ResourceKey key, string xmlContent, CompressionMode compressionMode = CompressionMode.Auto)
Parameters
key
ResourceKeyThe key of the resource
xmlContent
stringThe XML content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
Returns
SetXmlAsync(ResourceKey, string, CompressionMode, CancellationToken)
Sets the xmlContent
of a resource with the specified key
, returning true if the resource was compressed; otherwise, false
public Task<bool> SetXmlAsync(ResourceKey key, string xmlContent, CompressionMode compressionMode = CompressionMode.Auto, CancellationToken cancellationToken = default)
Parameters
key
ResourceKeyThe key of the resource
xmlContent
stringThe XML content of the resource
compressionMode
CompressionModeThe compression mode to use for the resource
cancellationToken
CancellationTokenThe token to monitor for cancellation requests
Returns
ZLibCompress(ReadOnlyMemory<byte>)
Compresses the specified memory
using ZLib, returning the result
public static ReadOnlyMemory<byte> ZLibCompress(ReadOnlyMemory<byte> memory)
Parameters
memory
ReadOnlyMemory<byte>
Returns
ZLibCompressAsync(ReadOnlyMemory<byte>, CancellationToken)
Compresses the specified memory
using ZLib asynchronously, returning the result
public static Task<ReadOnlyMemory<byte>> ZLibCompressAsync(ReadOnlyMemory<byte> memory, CancellationToken cancellationToken = default)
Parameters
memory
ReadOnlyMemory<byte>cancellationToken
CancellationToken
Returns
ZLibDecompress(ReadOnlyMemory<byte>, int)
Decompresses the specified memory
using ZLib, returning the result at the specified sizeDecompressed
public static ReadOnlyMemory<byte> ZLibDecompress(ReadOnlyMemory<byte> memory, int sizeDecompressed)
Parameters
memory
ReadOnlyMemory<byte>sizeDecompressed
int
Returns
ZLibDecompressAsync(ReadOnlyMemory<byte>, int, CancellationToken)
Decompresses the specified memory
using ZLib asynchronously, returning the result at the specified sizeDecompressed
public static Task<ReadOnlyMemory<byte>> ZLibDecompressAsync(ReadOnlyMemory<byte> memory, int sizeDecompressed, CancellationToken cancellationToken = default)
Parameters
memory
ReadOnlyMemory<byte>sizeDecompressed
intcancellationToken
CancellationToken