The DiskView view provides a low-level interface for reading from, and writing to, sectors on a CHS geometry disk image stored in an ArrayBuffer.
const data = readFileSync('my-disk.img');
const view = new DiskView(data.buffer, { tracks: 80, sides: 2, sectorsPerTrack: 10 });
const bootsector = view.getSector(1, 0, 0); // sector 1, track 0, side 0Creates a new DiskView instance.
instance = new DiskView(buffer)
instance = new DiskView(buffer, options)
instance = new DiskView(buffer, options, byteOffset)| Name | Type | Description |
|---|---|---|
buffer |
ArrayBuffer | An ArrayBuffer to use as the storage backing the new DiskView. |
options (Optional) |
DiskViewInitDict | The options for customising the new view instance. |
byteOffset (Optional) |
number | The offset into the buffer where the disk image data starts. Defaults to 0. |
Returns a Uint8Array containing the bytes of a single sector.
result = myDiskView.getSector(sector, track, side)| Name | Type | Description |
|---|---|---|
sector |
number | The sector to fetch. |
track |
number | The track containing the sector. |
side |
number | The side containing the sector. |
A Uint8Array. A Uint8Array containing the sector data.
Retrieves a Uint8Array containing the bytes of a single track.
result = myDiskView.getTrack(track)
result = myDiskView.getTrack(track, side)| Name | Type | Description |
|---|---|---|
track |
number | The track to fetch. |
side (Optional) |
number | The side containing the track. Defaults to 0. |
A Uint8Array. An Uint8Array containing the track data.
Replaces the bytes in a sector with new data.
myDiskView.setSector(sector, track, side, buffer)| Name | Type | Description |
|---|---|---|
sector |
number | The sector to fetch. |
track |
number | The track containing the sector. |
side |
number | The side containing the sector. |
buffer |
Uint8Array | The new data for the sector. Array length must match bytesPerSector. |
A ArrayBuffer. Gets the underlying ArrayBuffer backing this view.
A number. The offset into the buffer where the disk image data starts.
A number. Gets the number of bytes per sector.
A number. Gets the number of configured sides for the disk.
A number. Gets the number of configured tracks for the disk.
Represents a view over a FAT directory entry in a given ArrayBuffer. Allows reading and writing of file metadata such as filename, size, start cluster, and attributes.
Creates a new view of a FAT directory entry.
instance = new FatDirectoryEntryView(buffer)
instance = new FatDirectoryEntryView(buffer, byteOffset)| Name | Type | Description |
|---|---|---|
buffer |
ArrayBuffer | The buffer containing the FAT directory entry. |
byteOffset (Optional) |
number | Offset into the buffer where the entry starts. Defaults to 0. |
Returns the attribute byte for the entry (e.g. archive, hidden, system, etc).
result = myFatDirectoryEntryView.getAttributes()A number. The attribute byte.
Returns the filename of the entry the view represents.
result = myFatDirectoryEntryView.getName()A string. The filename of the entry.
Returns the file size in bytes stored in the entry.
result = myFatDirectoryEntryView.getSize()A number. The file size in bytes.
Returns the number of the cluster containing the first chunk of data for the entry's content.
result = myFatDirectoryEntryView.getStartCluster()A number. The starting cluster number.
Sets the attribute byte for the entry (e.g. archive, hidden, system, etc).
myFatDirectoryEntryView.setAttributes(value)| Name | Type | Description |
|---|---|---|
value |
number | The attribute byte. |
Sets the filename of the entry the view represents. Changes are made to the underlying ArrayBuffer.
myFatDirectoryEntryView.setName(value)| Name | Type | Description |
|---|---|---|
value |
string | The new filename. |
Sets the file size in bytes stored in the entry.
myFatDirectoryEntryView.setSize(value)| Name | Type | Description |
|---|---|---|
value |
number | The file size in bytes. |
Sets the number of the cluster containing the first chunk of data for the entry's content.
myFatDirectoryEntryView.setStartCluster(value)| Name | Type | Description |
|---|---|---|
value |
number | The starting cluster number. |
A ArrayBuffer. Gets the underlying ArrayBuffer.
A number. Gets the number of bytes in a FAT directory entry.
A number. Gets the offset into the buffer where this view starts.
The FatDiskView view provides a low-level interface for reading from, and writing to, files and directories on a FAT12 or FAT16 disk image stored in a binary ArrayBuffer.
const data = readFileSync('my-disk.img');
const view = new FatDiskView(data.buffer, { format: 'fat12' });
const rootDirEntries = view.getDirectoryContents();
console.log(rootDirEntries)Extends DiskView.
Creates a new FatDiskView instance.
instance = new FatDiskView(buffer)
instance = new FatDiskView(buffer, options)
instance = new FatDiskView(buffer, options, byteOffset)| Name | Type | Description |
|---|---|---|
buffer |
ArrayBuffer | An ArrayBuffer to use as the storage backing the new FatDiskView. |
options (Optional) |
FatDiskViewInitDict | The options for customising the new view instance. |
byteOffset (Optional) |
number | The offset into the buffer where the disk image data starts. Defaults to 0. |
Creates a new subdirectory within a specified directory entry. If no directory is specified, the subdirectory is created in the root directory.
result = myFatDiskView.createDirectory(name)
result = myFatDiskView.createDirectory(name, parentDirectory)| Name | Type | Description |
|---|---|---|
name |
string | The name of the new directory. |
parentDirectory (Optional) |
FatDirectoryEntryView | The parent of the new directory. Root if omitted. Defaults to null. |
A FatDirectoryEntryView. A FatDirectoryEntryView representing the new sub directory.
Creates a new empty directory at a fully qualified file path. The directory structure must exist.
result = myFatDiskView.createDirectoryAtPath(path)| Name | Type | Description |
|---|---|---|
path |
string | The path of the directory to create. |
A FatDirectoryEntryView. A file reference.
Creates an empty file in the specified directory (or in the root directory if none is provided) and returns a FatDirectoryEntryView representing the new file.
result = myFatDiskView.createFile(name)
result = myFatDiskView.createFile(name, parentDirectory)| Name | Type | Description |
|---|---|---|
name |
string | The file name of the file. |
parentDirectory (Optional) |
FatDirectoryEntryView | A FatDirectoryEntryView interface representing the directory that new file will be created in. Defaults to null. |
A FatDirectoryEntryView. A FatDirectoryEntryView for the new file entry.
Creates a new empty file at a fully qualified file path. The directory structure must exist.
result = myFatDiskView.createFileAtPath(path)| Name | Type | Description |
|---|---|---|
path |
string | The path of the file to create. |
A FatDirectoryEntryView. A file reference.
Retrieves a directory entry by name from the specified parent directory. If no parent is provided, the root directory is used.
result = myFatDiskView.getDirectory(name)
result = myFatDiskView.getDirectory(name, parentDirectory)| Name | Type | Description |
|---|---|---|
name |
string | The name of the directory to retrieve. |
parentDirectory (Optional) |
FatDirectoryEntryView | The parent directory to search in. Defaults to the root directory if not provided. Defaults to null. |
A FatDirectoryEntryView. The directory entry corresponding to the specified name.
Returns a reference to an existing directory at a fully qualified path. The parent directory structure must exist.
result = myFatDiskView.getDirectoryAtPath(path)| Name | Type | Description |
|---|---|---|
path |
string | The path of the directory to get a reference to. |
A FatDirectoryEntryView. The entry for the directory, or null if the path is resolves to the root directory.
Retrieves the directory entries from the specified parent directory. If no parent is provided, the root directory is used.
result = myFatDiskView.getDirectoryEntries()
result = myFatDiskView.getDirectoryEntries(directory)| Name | Type | Description |
|---|---|---|
directory (Optional) |
FatDirectoryEntryView | The directory to fetch files from. If omitted, the root directory is used. Defaults to null. |
A FatDirectoryEntryView[]. The entries for the directory.
Returns a FatEntryDataView interface for the file at the specified path.
result = myFatDiskView.getFile(name)
result = myFatDiskView.getFile(name, parentDirectory)| Name | Type | Description |
|---|---|---|
name |
string | |
parentDirectory (Optional) |
FatDirectoryEntryView | Defaults to null. |
A FatDirectoryEntryView.
Returns a FatDirectoryEntryView interface for the file at the specified path. If the file doesn't exist an exception is thrown.
result = myFatDiskView.getFileAtPath(path)| Name | Type | Description |
|---|---|---|
path |
string | The path of the file to access. |
A FatDirectoryEntryView. A file reference.
Retrieves the contents of a file represented by the given directory entry.
This method reads the FAT table to determine the chain of clusters used by the file, then reads the data from each cluster and assembles it into a single contiguous buffer.
result = myFatDiskView.getFileContents(entry)| Name | Type | Description |
|---|---|---|
entry |
FatDirectoryEntryView | The directory entry representing the file to read. |
A Uint8Array. A byte array containing the file's contents.
Returns the available free space on the disk, in bytes. The resulting value is computed from the number of unused clusters in the FAT table, so will be a multiple of the cluster size, as defined in the Bios Paramater Block.
result = myFatDiskView.getFree()A number.
The total number of bytes that can be stored on the volume.
result = myFatDiskView.getSize()A number.
Sets the binary content of a file represented by the given directory entry.
myFatDiskView.setFileContents(entry, contents)| Name | Type | Description |
|---|---|---|
entry |
FatDirectoryEntryView | The directory entry representing the file to write to. |
contents |
Uint8Array | A byte array or string containing the new contents. |
Extends Error.
instance = new FatError(message, name)| Name | Type | Description |
|---|---|---|
message |
string | The error message. |
name |
string | The error name. Allowed values: "WriteError" or "NotFoundError". |
A string. The name of the error.
Configuration options for creating a new DiskView instance.
| Name | Type | Description |
|---|---|---|
bytesPerSector (Optional) |
number | The number of bytes in a single sector. Defaults to 512. |
sectorsPerTrack (Optional) |
number | The number of sectors on each track. Defaults to 9. |
sides (Optional) |
number | The number of sides on the disk. Defaults to 2. |
tracks (Optional) |
number | The number of tracks on the disk. Defaults to 80. |
Configuration options for creating a new FatDiskView instance.
| Name | Type | Description |
|---|---|---|
format (Optional) |
string | The FAT format of the filesystem the view represents. Allowed values: "fat12" or "fat16". Defaults to "fat12". |