UNPKG

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

32 lines (31 loc) 1.24 kB
import {CFDataview} from "./dataview/СFDataview"; import {Header} from "./Header"; import {isFreeSectOrNoStream} from "./utils"; import * as Long from "long"; export class DifatEntries { private readonly view: CFDataview; private readonly difatEntries: number[] = []; constructor(dataView: CFDataview) { this.view = dataView; for (let i = 0; i < this.view.getSize(); i+=4) { const entry = this.view.subView(i, i+4).getData(); if(isFreeSectOrNoStream(entry)) { break; } this.difatEntries.push(Long.fromBytesLE(entry).toNumber()); } } getDifatEntries(): number[] { return this.difatEntries; } registerFatSector(sectorPosition: number): void { if(this.difatEntries.length >= Header.DIFAT_ENTRIES_LIMIT_IN_HEADER) { throw new Error("Unable to register additional FAT sector in Header"); } this.view.writeAt(this.difatEntries.length * 4, Long.fromValue(sectorPosition).to4BytesLE()); this.difatEntries.push(sectorPosition); } isFull(): boolean { return this.difatEntries.length >= Header.DIFAT_ENTRIES_LIMIT_IN_HEADER; } }