compound-binary-file-js
Version:
This is an implementation of [Compound Binary File v.3](https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-cfb/53989ce4-7b05-4f8d-829b-d08d6148375b) \ Allows reading existing files, creation of the/write operation
28 lines (24 loc) • 1.1 kB
text/typescript
import {AllocationTable} from "./AllocationTable";
import {Sector} from "../dataview/Sector";
import {FAT} from "./FAT";
import {Header} from "../Header";
import {Sectors} from "../Sectors";
export class MiniFAT extends AllocationTable {
private readonly header: Header;
private readonly fat: FAT;
constructor(sectors: Sectors, header: Header, fat: FAT) {
super(sectors, fat.buildChain(header.getFirstMinifatSectorLocation()), header.getSectorShift());
this.header = header;
this.fat = fat;
}
protected allocateNewSector(): Sector {
const newSector = super.allocateNewSector();
const previousSectorPosition = this.sectorChain.length === 1 ? null : this.sectorChain[this.sectorChain.length - 2];
this.fat.registerSector(newSector.getPosition(), previousSectorPosition);
this.header.setNumberOfMiniFatSectors(this.sectorChain.length);
if(this.sectorChain.length === 1) {
this.header.setFirstMinifatSectorLocation(this.sectorChain[0]);
}
return newSector;
}
}