Skip to content

Class VirtualDriveStorage ​

Source: virtualDriveStorage.ts

A wrapper for localStorage with additional functionality like compression and a size limit.

Extends ​

Constructors ​

Constructor ​

new VirtualDriveStorage(virtualDriveConfig: VirtualDriveConfig): VirtualDriveStorage

Parameters ​

virtualDriveConfig ​

VirtualDriveConfig

Returns ​

VirtualDriveStorage

Overrides ​

Storage.constructor

Properties ​

enableCompression ​

enableCompression: boolean = false

Enables compression of values stored in this storage.

Default ​

ts
false

Inherited from ​

Storage.enableCompression


prefix ​

prefix: string | undefined

The prefix to prepend to keys.

Default ​

ts
undefined

Inherited from ​

Storage.prefix


MAX_BYTES ​

readonly static MAX_BYTES: 5000000 = 5_000_000

The maximum amount of bytes of a value in this storage.

Inherited from ​

Storage.MAX_BYTES


COMPRESSED_PREFIX ​

readonly static COMPRESSED_PREFIX: "" = "\uE000"

Inherited from ​

Storage.COMPRESSED_PREFIX


UNCOMPRESSED_PREFIX ​

readonly static UNCOMPRESSED_PREFIX: "" = "\uE001"

Inherited from ​

Storage.UNCOMPRESSED_PREFIX


virtualDriveConfig ​

virtualDriveConfig: VirtualDriveConfig


KEY ​

readonly static KEY: "drive" = "drive"

Methods ​

rename() ​

rename(oldKey: string, newKey: string): this

Replaces the key of an item if it exists.

Parameters ​

oldKey ​

string

The key to replace.

newKey ​

string

The new key.

Returns ​

this

Inherited from ​

Storage.rename


remove() ​

remove(key: string): this

Removes the item with the given key from this storage.

Parameters ​

key ​

string

The key of the item.

Returns ​

this

Inherited from ​

Storage.remove


clear() ​

clear(): this

Clears all items stored in this storage.

Returns ​

this

Inherited from ​

Storage.clear


getItemByteSize() ​

getItemByteSize(key: string, value: string): number

Returns the byte size of a key and value pair.

Parameters ​

key ​

string

The key of the item.

value ​

string

The value of the item.

Returns ​

number

Inherited from ​

Storage.getItemByteSize


getEncodedByteSize() ​

getEncodedByteSize(string: string | null): number

Parameters ​

string ​

string | null

Returns ​

number

Inherited from ​

Storage.getEncodedByteSize


encode() ​

encode(string: string): { result: string; size: number; }

Parameters ​

string ​

string

Returns ​

{ result: string; size: number; }

result ​

result: string

size ​

size: number

Inherited from ​

Storage.encode


decode() ​

decode(string: string): string

Parameters ​

string ​

string

Returns ​

string

Inherited from ​

Storage.decode


setPrefix() ​

setPrefix(prefix?: string): this

Parameters ​

prefix? ​

string

Returns ​

this

Inherited from ​

Storage.setPrefix


getByteSize() ​

static getByteSize(string: string | null): number

Parameters ​

string ​

string | null

Returns ​

number

Inherited from ​

Storage.getByteSize


byteToKilobyte() ​

static byteToKilobyte(bytes: number): number

Parameters ​

bytes ​

number

Returns ​

number

Inherited from ​

Storage.byteToKilobyte


load() ​

load(key: string): string | null

Loads a value associated with the given key.

Parameters ​

key ​

string

The key of the item.

Returns ​

string | null

The value of the item.

Overrides ​

Storage.load


store() ​

store(key: string, value: string): void

Stores a key and value pair in this storage.

Parameters ​

key ​

string

The key to store.

value ​

string

The value to store.

Returns ​

void

Overrides ​

Storage.store


synchronize() ​

synchronize(): void

Returns ​

void

Built by Prozilla