Table of Contents

Class BinaryStorage

Namespace
NanoByte.Common.Storage
Assembly
NanoByte.Common.dll

Provides easy serialization to binary files (optionally wrapped in ZIP archives).

public static class BinaryStorage
Inheritance
BinaryStorage

Methods

LoadBinary<T>(Stream)

Loads an object from a binary file.

public static T LoadBinary<T>(Stream stream)

Parameters

stream Stream

The binary file to be loaded.

Returns

T

The loaded object.

Type Parameters

T

The type of object the binary stream shall be converted into.

Exceptions

InvalidDataException

A problem occurred while deserializing the binary data.

LoadBinary<T>(string)

Loads an object from a binary file.

public static T LoadBinary<T>(string path)

Parameters

path string

The binary file to be loaded.

Returns

T

The loaded object.

Type Parameters

T

The type of object the binary stream shall be converted into.

Remarks

Uses see cref="AtomicRead"/> internally.

Exceptions

IOException

A problem occurred while reading the file.

UnauthorizedAccessException

Read access to the file is not permitted.

InvalidDataException

A problem occurred while deserializing the binary data.

SaveBinary<T>(T, Stream)

Saves an object in a binary stream.

public static void SaveBinary<T>(this T data, Stream stream) where T : notnull

Parameters

data T

The object to be stored.

stream Stream

The binary file to be written.

Type Parameters

T

The type of object to be saved in a binary stream.

SaveBinary<T>(T, string)

Saves an object in a binary file.

public static void SaveBinary<T>(this T data, string path) where T : notnull

Parameters

data T

The object to be stored.

path string

The binary file to be written.

Type Parameters

T

The type of object to be saved in a binary stream.

Remarks

This method performs an atomic write operation when possible.

Exceptions

IOException

A problem occurred while writing the file.

UnauthorizedAccessException

Write access to the file is not permitted.