VolumeDriverFile

VolumeDriverFile

File based volume driver.

Constructor

new VolumeDriverFile(path, optsopt)

Description:
  • Constructor for the class.

Source:
Example
const VolumeDriverFile = require('volume-driver-file');
const driver = new VolumeDriverFile('/path/to/file', {readOnly: false});
const buffer = Buffer.alloc(512);
driver.readSectors(0, buffer, () => {});
driver.writeSectors(0, buffer, () => {});
driver.close();
Parameters:
Name Type Attributes Default Description
path string

The path to the file.

opts object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
readOnly boolean <optional>
false

Flag to indicate if the file should be opened in read-only mode.

partitionNumber number <optional>
0

The partition number.

Throws:

If the file does not exist.

Type
Error

Extends

Members

numSectors

Description:
  • Returns the number of sectors.

Source:
Overrides:

Returns the number of sectors.

numSectors

Description:
  • Returns the number of sectors.

Source:
Overrides:

Returns the number of sectors.

partitionNumber

Description:
  • Get the value of the partitionNumber property.

Source:
Overrides:

Get the value of the partitionNumber property.

partitionOffsetBytes

Description:
  • Returns the offset bytes for the currently selected partition

Source:
Overrides:

Returns the offset bytes for the currently selected partition

readOnly

Description:
  • Get the value of the readOnly property.

Source:
Overrides:

Get the value of the readOnly property.

sectorSize

Description:
  • Get the sector size.

Source:
Overrides:

Get the sector size.

Methods

checkSectorLength(dest)

Description:
  • Checks if the length of a destination buffer is a multiple of the sector size.

Source:
Overrides:
Parameters:
Name Type Description
dest any

The destination buffer to check.

Throws:

Throws an error if the buffer length is not a multiple of the sector size.

Type
Error

parsePartitionsFromBuffer(buffer) → {Array}

Description:
  • Parses partitions from a buffer. Reads a FAT16 MBR and returns an array of partition offsets.

Source:
Overrides:
Parameters:
Name Type Description
buffer Buffer

The buffer to parse partitions from.

Returns:

An array of partition offsets.

Type
Array

readPartitions() → {Array}

Description:
  • Reads the partitions from the disk.

Source:
Overrides:
Returns:

An array of parsed partitions.

Type
Array

readPartitions() → {Array}

Description:
  • Reads the partitions from the disk.

Source:
Overrides:
Returns:

An array of parsed partitions.

Type
Array

readSectors(i, dest, cb) → {void}

Description:
  • Reads sectors from a file.

Source:
Overrides:
Parameters:
Name Type Description
i number

the index of the sector to read

dest Buffer

the buffer to store the sector data

cb function

the callback function to be called with the results

Returns:
Type
void

readSectors(i, dest, cb) → {void}

Description:
  • Reads sectors from a file.

Source:
Overrides:
Parameters:
Name Type Description
i number

the index of the sector to read

dest Buffer

the buffer to store the sector data

cb function

the callback function to be called with the results

Returns:
Type
void

writeSectors(i, data, cb) → {void}

Description:
  • Writes the specified data to the sectors starting at index i.

Source:
Overrides:
Parameters:
Name Type Description
i number

The starting index of the sectors to write to.

data Buffer

The data to write to the sectors.

cb function

The callback function to be called when the write operation is completed.

Returns:
Type
void

writeSectors(i, data, cb) → {void}

Description:
  • Writes the specified data to the sectors starting at index i.

Source:
Overrides:
Parameters:
Name Type Description
i number

The starting index of the sectors to write to.

data Buffer

The data to write to the sectors.

cb function

The callback function to be called when the write operation is completed.

Returns:
Type
void

VolumeDriverFile

File based volume driver.

Constructor

new VolumeDriverFile(path, optsopt)

Description:
  • Constructor for the class.

Source:
Example
const VolumeDriverFile = require('volume-driver-file');
const driver = new VolumeDriverFile('/path/to/file', {readOnly: false});
const buffer = Buffer.alloc(512);
driver.readSectors(0, buffer, () => {});
driver.writeSectors(0, buffer, () => {});
driver.close();
Parameters:
Name Type Attributes Default Description
path string

The path to the file.

opts object <optional>
{}

Optional parameters.

Properties
Name Type Attributes Default Description
readOnly boolean <optional>
false

Flag to indicate if the file should be opened in read-only mode.

partitionNumber number <optional>
0

The partition number.

Throws:

If the file does not exist.

Type
Error

Extends

Members

numSectors

Description:
  • Returns the number of sectors.

Source:
Overrides:

Returns the number of sectors.

numSectors

Description:
  • Returns the number of sectors.

Source:
Overrides:

Returns the number of sectors.

partitionNumber

Description:
  • Get the value of the partitionNumber property.

Source:
Overrides:

Get the value of the partitionNumber property.

partitionOffsetBytes

Description:
  • Returns the offset bytes for the currently selected partition

Source:
Overrides:

Returns the offset bytes for the currently selected partition

readOnly

Description:
  • Get the value of the readOnly property.

Source:
Overrides:

Get the value of the readOnly property.

sectorSize

Description:
  • Get the sector size.

Source:
Overrides:

Get the sector size.

Methods

checkSectorLength(dest)

Description:
  • Checks if the length of a destination buffer is a multiple of the sector size.

Source:
Overrides:
Parameters:
Name Type Description
dest any

The destination buffer to check.

Throws:

Throws an error if the buffer length is not a multiple of the sector size.

Type
Error

parsePartitionsFromBuffer(buffer) → {Array}

Description:
  • Parses partitions from a buffer. Reads a FAT16 MBR and returns an array of partition offsets.

Source:
Overrides:
Parameters:
Name Type Description
buffer Buffer

The buffer to parse partitions from.

Returns:

An array of partition offsets.

Type
Array

readPartitions() → {Array}

Description:
  • Reads the partitions from the disk.

Source:
Overrides:
Returns:

An array of parsed partitions.

Type
Array

readPartitions() → {Array}

Description:
  • Reads the partitions from the disk.

Source:
Overrides:
Returns:

An array of parsed partitions.

Type
Array

readSectors(i, dest, cb) → {void}

Description:
  • Reads sectors from a file.

Source:
Overrides:
Parameters:
Name Type Description
i number

the index of the sector to read

dest Buffer

the buffer to store the sector data

cb function

the callback function to be called with the results

Returns:
Type
void

readSectors(i, dest, cb) → {void}

Description:
  • Reads sectors from a file.

Source:
Overrides:
Parameters:
Name Type Description
i number

the index of the sector to read

dest Buffer

the buffer to store the sector data

cb function

the callback function to be called with the results

Returns:
Type
void

writeSectors(i, data, cb) → {void}

Description:
  • Writes the specified data to the sectors starting at index i.

Source:
Overrides:
Parameters:
Name Type Description
i number

The starting index of the sectors to write to.

data Buffer

The data to write to the sectors.

cb function

The callback function to be called when the write operation is completed.

Returns:
Type
void

writeSectors(i, data, cb) → {void}

Description:
  • Writes the specified data to the sectors starting at index i.

Source:
Overrides:
Parameters:
Name Type Description
i number

The starting index of the sectors to write to.

data Buffer

The data to write to the sectors.

cb function

The callback function to be called when the write operation is completed.

Returns:
Type
void