Table of Contents

Namespace NanoByte.Common.Storage

File system access and serialization.

The following types help with bulk operations and are also usable as ITasks for progress reporting:

Atomic writes

To avoid leaving partially-written files behind on crashes or process kills, write to a temporary path first and only replace the target on success:

  • AtomicWrite writes to a temporary file and atomically moves it into place on Dispose().
  • AtomicRead takes a matching read lock.

Temporary paths

The following types create unique paths on construction and delete them on Dispose():

Locations

Locations resolves cross-platform paths for application data, caches and configuration following the XDG Base Directory Specification on Unix and the matching Windows conventions.

Serialization

The following static classes provide shorthand load/save methods for the common serialization formats. They use atomic writes by default.

API

Classes

AtomicRead

Ensures that a read operation for a file does not conflict with an AtomicWrite for the same file.

AtomicWrite

Provides a temporary path to write to and atomically inserts it at the destination location on disposal (if Commit() was called).

BinaryStorage

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

CopyDirectory

Copies the content of a directory to a new location preserving file timestamps, symlinks and hard links.

FileUtils

Provides filesystem-related helper methods.

JsonStorage

Provides easy serialization to JSON files.

Locations

Provides easy access to platform-specific common directories for storing settings and application data.

MoveDirectory

Moves the content of a directory to a new location preserving file timestamps, symlinks and hard links.

Paths

Helper methods for resolving file system paths.

ReadDirectoryBase

Recursively iterates over all elements in a directory.

ReadFile

Reads a file from disk to a stream.

TemporaryDirectory

Represents a temporary directory that is automatically deleted when the object is disposed.

TemporaryFile

Represents a temporary file that is automatically deleted when the object is disposed.

TemporaryFlagFile

A temporary directory with a file that may or may not exist to indicate whether a certain condition is true or false.

TemporaryWorkingDirectory

Like TemporaryDirectory but also sets the current working directory to Path.

WorkingDirectory

Changes the current working working directory until the object is disposed.

XmlNamespaceAttribute

Allows you to specify a XmlQualifiedName (namespace short-name) for XmlStorage to use.

XmlStorage

Provides easy serialization to XML files.