Class: module:blockstore:FileBlockStore

(abstract) module:blockstore:FileBlockStore()

File Block Store

Constructor

(abstract) new module:blockstore:FileBlockStore()

Create a blockstore that stores blocks in files.

Source:

Methods

(async, private) _index(type) → {Promise}

Creates indexes from files for a block type. Reads the hash of the block data from the magic prefix, except for a block which the hash is read from the block header.

Parameters:
Name Type Description
type Number

The type of block data

Source:
Returns:
Type
Promise

(async, private) _prune(hash) → {Promise}

This will free resources for storing the block data. The block data may not be deleted from disk immediately, the index for the block is removed and will not be able to be read. The underlying file is unlinked when all blocks in a file have been pruned.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async, private) _read(type, hash, offset, length) → {Promise}

This methods reads data from disk by retrieving the index of the data and reading from the corresponding file and location.

Parameters:
Name Type Description
type Number

The type of block data

hash Buffer

The block hash

offset Number

The offset within the block

length Number

The number of bytes of the data

Source:
Returns:
Type
Promise

(async, private) _write(type, hash, data) → {Promise}

This method stores block data in files with by appending data to the last written file and updating indexes to point to the file and position.

Parameters:
Name Type Description
type Number

The type of block data

hash Buffer

The block hash

data Buffer

The block data

Source:
Returns:
Type
Promise

(async, private) allocate(type, length) → {Promise}

This method will select and potentially allocate a file to write a block based on the size and type.

Parameters:
Name Type Description
type Number

The type of block data

length Number

The number of bytes

Source:
Returns:
Type
Promise

batch() → {FileBatch}

Create batch.

Source:
Returns:
Type
FileBatch

(async, private) check(type) → {Promise.<Object>}

Compares the number of files in the directory with the recorded number of files.

Parameters:
Name Type Description
type Number

The type of block data

Source:
Returns:
Type
Promise.<Object>

(async) close()

This closes the file block store and underlying indexing databases.

Source:

(async) ensure() → {Promise}

This method ensures that both the block storage directory and index directory exist. before opening.

Source:
Returns:
Type
Promise

(private) filepath(type, fileno) → {Promise}

This method will determine the file path based on the file number and the current block data location.

Parameters:
Name Type Description
type Number

The type of block data

fileno Number

The number of the file.

Source:
Returns:
Type
Promise

(async) hasBlock(hash) → {Promise}

This will check if a block has been stored and is available.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) hasMerkle(hash) → {Promise}

This will check if merkle block data has been stored and is available.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) hasUndo(hash) → {Promise}

This will check if a block undo coin has been stored and is available.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async, private) index() → {Promise}

Compares the number of files in the directory with the recorded number of files. If there are any inconsistencies it will reindex all blocks.

Source:
Returns:
Type
Promise

(async) open() → {Promise}

Opens the file block store. It will regenerate necessary block indexing if the index is missing or inconsistent.

Source:
Returns:
Type
Promise

(async) pruneBlock(hash) → {Promise}

This will free resources for storing the block data.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) pruneMerkle(hash) → {Promise}

This will free resources for storing merkle block data.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) pruneUndo(hash) → {Promise}

This will free resources for storing the block undo coin data.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) readBlock(hash, offset, length) → {Promise}

This method will retrieve block data. Smaller portions of the block (e.g. transactions) can be read by using the offset and length arguments.

Parameters:
Name Type Description
hash Buffer

The block hash

offset Number

The offset within the block

length Number

The number of bytes of the data

Source:
Returns:
Type
Promise

(async) readMerkle(hash) → {Promise}

This method will retrieve merkle block data.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) readUndo(hash) → {Promise}

This method will retrieve block undo coin data.

Parameters:
Name Type Description
hash Buffer

The block hash

Source:
Returns:
Type
Promise

(async) writeBlock(hash, data) → {Promise}

This method stores block data in files.

Parameters:
Name Type Description
hash Buffer

The block hash

data Buffer

The block data

Source:
Returns:
Type
Promise

(async) writeMerkle(hash, data) → {Promise}

This method stores merkle block data in files.

Parameters:
Name Type Description
hash Buffer

The block hash

data Buffer

The block data

Source:
Returns:
Type
Promise

(async) writeUndo(hash, data) → {Promise}

This method stores block undo coin data in files.

Parameters:
Name Type Description
hash Buffer

The block hash

data Buffer

The block data

Source:
Returns:
Type
Promise