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

58 lines (46 loc) 1.45 kB
import {Sector} from "./Sector"; import {CFDataview} from "./СFDataview"; export class SimpleSector implements Sector { private readonly view: CFDataview; private readonly position: number; constructor(view: CFDataview, position: number) { this.view = view; this.position = position; } getPosition(): number { return this.position; } writeAt(position: number, bytes: number[]): Sector { this.view.writeAt(position, bytes); return this; } getSize(): number { return this.view.getSize(); } getData(): number[] { return this.view.getData(); } subView(start: number, end?: number): CFDataview { return this.view.subView(start, end); } allocate(length: number): CFDataview { return this.view.allocate(length); } fill(filler: number[]): Sector { this.view.fill(filler); return this; } readAt(position: number, length: number): number[] { return this.view.readAt(position, length); } static from(view: CFDataview, position: number, filler?: number[]): Sector { const simpleSector = new SimpleSector(view, position); if(filler != null) { simpleSector.fill(filler); } return simpleSector; } isEmpty(): boolean { return this.getSize() === 0; } }