Struct CompressionResult
Represents the outcome of a void-returning ScyllaCompression operation (such as file-to-file compression or archive extraction) using the result pattern instead of exceptions.
Inherited Members
Namespace: Scylla.Core.Util.Compression
Assembly: ScyllaCore.dll
Syntax
public readonly struct CompressionResult
Remarks
Use this type - and its generic counterpart CompressionResult<T> - when you prefer to avoid exception-based control flow. Factory methods Success() and Failure(CompressionErrorCode, string, Exception) are the only way to construct instances; the constructor is private.
The recommended usage pattern is to check IsSuccess before accessing error properties:
var result = ScyllaCompression.CompressFileToResult(sourcePath, destPath);
if (!result.IsSuccess)
{
Debug.LogError($"[{result.ErrorCode}] {result.ErrorMessage}");
return;
}
When IsSuccess is true, ErrorCode is set to
Unknown as a neutral sentinel. Do not use the
error code value on a successful result.
Properties
ErrorCode
Gets the structured error code that categorizes the failure when
IsFailure is true. Returns
Unknown on successful results as a neutral
sentinel - always check IsSuccess first.
Declaration
public CompressionErrorCode ErrorCode { get; }
Property Value
| Type | Description |
|---|---|
| CompressionErrorCode |
ErrorMessage
Gets a human-readable description of the failure when IsFailure is
true. Returns null for successful results.
Declaration
public string ErrorMessage { get; }
Property Value
| Type | Description |
|---|---|
| string |
Exception
Gets the underlying exception that caused the failure, if one was captured.
Returns null when the failure was generated without an underlying exception,
or when the operation succeeded.
Declaration
public Exception Exception { get; }
Property Value
| Type | Description |
|---|---|
| Exception |
IsFailure
Gets a value indicating whether the compression operation failed.
Equivalent to !IsSuccess. When true, ErrorCode,
ErrorMessage, and Exception carry diagnostic information.
Declaration
public bool IsFailure { get; }
Property Value
| Type | Description |
|---|---|
| bool |
IsSuccess
Gets a value indicating whether the compression operation completed successfully.
When true, ErrorCode, ErrorMessage, and
Exception are meaningless and should not be read.
Declaration
public bool IsSuccess { get; }
Property Value
| Type | Description |
|---|---|
| bool |
Methods
Failure(CompressionErrorCode, string, Exception)
Creates a CompressionResult that represents a failed operation with a structured error code and optional diagnostic details.
Declaration
public static CompressionResult Failure(CompressionErrorCode errorCode, string errorMessage = null, Exception exception = null)
Parameters
| Type | Name | Description |
|---|---|---|
| CompressionErrorCode | errorCode | The CompressionErrorCode that categorizes the failure. |
| string | errorMessage | A human-readable description of the failure. When |
| Exception | exception | The underlying exception that caused the failure, or |
Returns
| Type | Description |
|---|---|
| CompressionResult | A CompressionResult where IsSuccess is |
FromException(CompressionException)
Creates a CompressionResult that represents a failure by extracting all diagnostic information from an existing CompressionException.
Declaration
public static CompressionResult FromException(CompressionException exception)
Parameters
| Type | Name | Description |
|---|---|---|
| CompressionException | exception | The CompressionException to convert. When |
Returns
| Type | Description |
|---|---|
| CompressionResult | A CompressionResult where IsSuccess is |
Success()
Creates a CompressionResult that represents a successful completion with no return value.
Declaration
public static CompressionResult Success()
Returns
| Type | Description |
|---|---|
| CompressionResult | A CompressionResult where IsSuccess is |