Constructor
(abstract) new module:blockstore:FileBlockStore(optionsopt)
Create a blockstore that stores blocks in files.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
options |
Object |
<optional> |
- 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(type, hash) → {Promise.<Boolean>}
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 |
---|---|---|
type |
Number | The type of block data |
hash |
Buffer | The block hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async, private) _read(type, hash, offsetopt, lengthopt) → {Promise.<Buffer>}
This methods reads data from disk by retrieving the index of the data and reading from the corresponding file and location.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
Number | The type of block data |
|
hash |
Buffer | The block hash |
|
offset |
Number |
<optional> |
The offset within the block |
length |
Number |
<optional> |
The number of bytes of the data |
- Source:
Returns:
- Type
- Promise.<Buffer>
(async, private) _write(type, hash, data) → {Promise.<Boolean>}
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:
- Whether the data was written.
- Type
- Promise.<Boolean>
(async, private) allocate(type, length) → {Promise.<Object>}
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.<Object>
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) → {String}
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
- String
(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.<Boolean>}
This will free resources for storing the block data.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Buffer | The block hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) pruneMerkle(hash) → {Promise.<Boolean>}
This will free resources for storing merkle block data.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Buffer | The block hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(async) pruneUndo(hash) → {Promise.<Boolean>}
This will free resources for storing the block undo coin data.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Buffer | The block hash |
- Source:
Returns:
- Type
- Promise.<Boolean>
(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.<Buffer>}
This method will retrieve merkle block data.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Buffer | The block hash |
- Source:
Returns:
- Type
- Promise.<Buffer>
(async) readUndo(hash) → {Promise.<Buffer>}
This method will retrieve block undo coin data.
Parameters:
Name | Type | Description |
---|---|---|
hash |
Buffer | The block hash |
- Source:
Returns:
- Type
- Promise.<Buffer>
(async) writeBlock(hash, data) → {Promise.<Boolean>}
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.<Boolean>
(async) writeMerkle(hash, data) → {Promise.<Boolean>}
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.<Boolean>
(async) writeUndo(hash, data) → {Promise.<Boolean>}
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.<Boolean>