Table of Contents

Class KeyValueStorageProvider

Namespace
VpnHood.AppLib.App
Assembly
VpnHood.AppLib.App.dll

Provides the app's files as entries of a key-value store the platform keeps where it keeps no files, such as tvOS's defaults: one entry per file, named by its path under a root folder.

public abstract class KeyValueStorageProvider : IStorageProvider
Inheritance
KeyValueStorageProvider
Implements
Inherited Members

Remarks

Such a store is small (tvOS ends an app whose defaults reach 1 MB), so the entries share a budget, and a write past it fails with the old content kept. The entries' keys start with VpnHood.AppFiles/; the store's other keys count for nothing.

Constructors

KeyValueStorageProvider(string, long)

Initializes a new instance of the KeyValueStorageProvider class.

protected KeyValueStorageProvider(string rootFolderPath, long budget)

Parameters

rootFolderPath string

The folder the files' paths must be under, which their keys are relative to.

budget long

The most the entries may take together, in bytes of UTF-8, their keys counted.

Methods

Delete(string)

Deletes a file; a missing one is passed over.

public void Delete(string filePath)

Parameters

filePath string

The file's full path.

Exceptions

ArgumentException

filePath is outside the root folder.

GetKeys()

Returns every key of the platform's store, this provider's own and others'.

protected abstract IReadOnlyList<string> GetKeys()

Returns

IReadOnlyList<string>

The keys.

GetSignature(string)

Gets a signature of a file, read without its content, which changes when the file is written as a rule: a write that keeps what the signature reads, such as a file's time and length, shows no change.

public string GetSignature(string filePath)

Parameters

filePath string

The file's full path.

Returns

string

The signature.

Remarks

Unlike a file's, it reads the entry's whole value: an entry has no time of its own, so the signature is the start of its value's SHA-256 hash, or none.

Exceptions

ArgumentException

filePath is outside the root folder.

GetValue(string)

Reads an entry of the platform's store.

protected abstract string? GetValue(string key)

Parameters

key string

The entry's key.

Returns

string

The entry's value, or null where there is none.

Read(string)

Reads a file's text.

public string? Read(string filePath)

Parameters

filePath string

The file's full path.

Returns

string

The text, or null when there is no such file.

Exceptions

ArgumentException

filePath is outside the root folder.

RemoveValue(string)

Removes an entry of the platform's store, if there is one.

protected abstract void RemoveValue(string key)

Parameters

key string

The entry's key.

SetValue(string, string)

Writes an entry of the platform's store.

protected abstract void SetValue(string key, string value)

Parameters

key string

The entry's key.

value string

The value.

Write(string, string)

Writes a file's text, whole or not at all: a write the provider cannot keep fails, and the old text stays.

public void Write(string filePath, string content)

Parameters

filePath string

The file's full path.

content string

The text.

Exceptions

ArgumentException

filePath is outside the root folder.

IOException

The write would take the entries past the budget; the old content is kept.