Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BinaryFile

The BinaryFile object is used to read and write files in binary mode.

When using BinaryFile.WriteOnly, you need to call commit when you’re done writing otherwise the operation will be aborted without effect.

To read and write files in text mode, use TextFile instead.

Hierarchy

  • BinaryFile

Index

Constructors

constructor

  • Opens a binary file in the given mode.

Properties

Readonly atEof

atEof: boolean

True if no more data can be read.

Readonly filePath

filePath: string

The path of the file.

pos

pos: number

The position that data is written to or read from.

size

size: number

The size of the file (in bytes).

Static Readonly ReadOnly

ReadOnly: typeof ReadOnly

Static Readonly ReadWrite

ReadWrite: typeof ReadWrite

Static Readonly WriteOnly

WriteOnly: typeof WriteOnly

Methods

close

  • close(): void
  • Closes the file. It is recommended to always call this function as soon as you are finished with the file.

commit

  • commit(): void
  • Commits all written data to disk and closes the file. Should be called when writing to files in WriteOnly mode. Failing to call this function will result in cancelling the operation, unless safe writing to files is disabled.

read

  • read(size: number): ArrayBuffer
  • Reads at most size bytes of data from the file and returns it as an ArrayBuffer.

readAll

  • readAll(): ArrayBuffer
  • Reads all data from the file and returns it as an ArrayBuffer.

resize

  • resize(size: number): void
  • Sets the file size (in bytes). If size is larger than the file currently is, the new bytes will be set to 0; if size is smaller, the file is truncated.

seek

  • seek(pos: number): void
  • Sets the current position to pos.

write

  • write(data: ArrayBuffer): void
  • Writes data into the file at the current position.

Generated using TypeDoc