Options
All
  • Public
  • Public/Protected
  • All
Menu

Class BinaryWriter

Writes primitive types in binary to a file and supports writing strings in a specific encoding.

Hierarchy

  • BinaryWriter

Index

Constructors

constructor

  • Initializes a new instance of the BinaryWriter class based on the specified IFile instance and character encoding, and optionally leaves the file open.

    Parameters

    • output: IFile

      The output file, expecting an IFile instance.

    • Default value encoding: BufferEncoding | string | IEncoding = "utf8"

      The character encoding to use, or an object implementing the IEncoding interface. Default to 'utf8'

    • Default value leaveOpen: boolean = false

      true to leave the file open after the BinaryWriter object is disposed; otherwise, false.

    Returns BinaryWriter

Properties

Private _disposed

_disposed: boolean = false

Private Readonly _encoding

_encoding: IEncoding

Protected _file

_file: IFile

Private Readonly _leaveOpen

_leaveOpen: boolean = false

Accessors

file

  • Returns the file associated with the writer. It flushes all pending writes before returning. All subclasses should override flush to ensure that all buffered data is sent to the file.

    Returns IFile

Static null

Methods

close

  • close(): void
  • Closes this writer and releases any system resources associated with the writer. Following a call to Close, any operations on the writer may raise exceptions.

    Returns void

flush

  • flush(): void
  • Clears all buffers for this writer and causes any buffered data to be written to the underlying device.

    Returns void

Private throwIfDisposed

  • throwIfDisposed(): void

write7BitEncodedInt

  • write7BitEncodedInt(value: number): void
  • Writes a 32-bit integer in a compressed format.

    Parameters

    • value: number

      The 32-bit integer to be written.

    Returns void

write7BitEncodedInt64

  • write7BitEncodedInt64(value: bigint): void
  • Writes a 64-bit integer in a compressed format.

    Parameters

    • value: bigint

      The 64-bit integer to be written.

    Returns void

writeBoolean

  • writeBoolean(value: boolean): void
  • Writes a one-byte Boolean value to the current file, with 0 representing false and 1 representing true.

    Parameters

    • value: boolean

      The Boolean value to write (0 or 1).

    Returns void

writeBuffer

  • writeBuffer(buffer: Buffer): void
  • Writes a byte array to the underlying file.

    Parameters

    • buffer: Buffer

      A byte array containing the data to write.

    Returns void

writeBufferEx

  • writeBufferEx(buffer: Buffer, index: number, count: number): void
  • Writes a region of a byte array to the current file.

    Parameters

    • buffer: Buffer

      A byte array containing the data to write.

    • index: number

      The index of the first byte to read from buffer and to write to the file.

    • count: number

      The number of bytes to read from buffer and to write to the file.

    Returns void

writeByte

  • writeByte(value: number): void
  • Writes an unsigned byte to the current file and advances the file position by one byte.

    Parameters

    • value: number

      The unsigned byte to write.

    Returns void

writeCString

  • writeCString(value: string): void
  • Write a null-terminated string to this file in the current encoding of the BinaryWriter, and advances the current position of the file in accordance with the encoding used and the specific characters being written to the file.

    Parameters

    • value: string

      The value to write.

    Returns void

writeChar

  • writeChar(ch: char): void
  • Writes a Unicode character to the current file and advances the current position of the file in accordance with the Encoding used and the specific characters being written to the file.

    Parameters

    • ch: char

      The non-surrogate, Unicode character to write.

    Returns void

writeChars

  • writeChars(chars: char[]): void
  • Writes a character array to the current file and advances the current position of the file in accordance with the Encoding used and the specific characters being written to the file.

    Parameters

    • chars: char[]

      A character array containing the data to write.

    Returns void

writeCharsEx

  • writeCharsEx(chars: char[], index: number, count: number): void
  • Writes a section of a character array to the current file, and advances the current position of the file in accordance with the Encoding used and perhaps the specific characters being written to the file.

    Parameters

    • chars: char[]

      A character array containing the data to write.

    • index: number

      The index of the first character to read from chars and to write to the stream.

    • count: number

      The number of characters to read from chars and to write to the stream.

    Returns void

writeDouble

  • writeDouble(value: number): void
  • Writes an eight-byte floating-point value to the current file and advances the file position by eight bytes.

    Parameters

    • value: number

      The eight-byte floating-point value to write.

    Returns void

writeInt16

  • writeInt16(value: number): void
  • Writes a two-byte signed integer to the current file and advances the file position by two bytes.

    Parameters

    • value: number

      The two-byte signed integer to write.

    Returns void

writeInt32

  • writeInt32(value: number): void
  • Writes a four-byte signed integer to the current file and advances the file position by four bytes.

    Parameters

    • value: number

      The four-byte signed integer to write.

    Returns void

writeInt64

  • writeInt64(value: bigint): void
  • Writes an eight-byte signed integer to the current file and advances the file position by eight bytes.

    Parameters

    • value: bigint

      The eight-byte signed integer to write.

    Returns void

writeRawString

  • writeRawString(value: string): void
  • Write a plain string to this file in the current encoding of the BinaryWriter, and advances the current position of the file in accordance with the encoding used and the specific characters being written to the file.

    Parameters

    • value: string

      The value to write.

    Returns void

writeSByte

  • writeSByte(value: number): void
  • Writes a signed byte to the current file and advances the file position by one byte.

    Parameters

    • value: number

    Returns void

writeSingle

  • writeSingle(value: number): void
  • Writes a four-byte floating-point value to the current file and advances the file position by four bytes.

    Parameters

    • value: number

      The four-byte floating-point value to write.

    Returns void

writeString

  • writeString(value: string): void
  • Writes a length-prefixed string to this file in the current encoding of the BinaryWriter, and advances the current position of the file in accordance with the encoding used and the specific characters being written to the file.

    Parameters

    • value: string

      The value to write.

    Returns void

writeUInt16

  • writeUInt16(value: number): void
  • Writes a two-byte unsigned integer to the current file and advances the file position by two bytes.

    Parameters

    • value: number

      The two-byte unsigned integer to write.

    Returns void

writeUInt32

  • writeUInt32(value: number): void
  • Writes a four-byte unsigned integer to the current file and advances the file position by four bytes.

    Parameters

    • value: number

      The four-byte unsigned integer to write.

    Returns void

writeUInt64

  • writeUInt64(value: bigint): void
  • Writes an eight-byte unsigned integer to the current file and advances the file position by eight bytes.

    Parameters

    • value: bigint

      The eight-byte unsigned integer to write.

    Returns void

Generated using TypeDoc