BinaryReader (object)

バージョン 1.12.0 で追加.

The BinaryReader is used to read binary data from files. It supports reading of any shallow data structure represented as a Data pointer and a DataSize.

BinaryReader BinaryReader BinaryReader FileReader FileReader BinaryReader->FileReader

/*
** Example: BinaryReader
*/

require FileIO;
  
operator entry() {

  FilePath path = FilePath('${TEMP}/binaryWriter.bin').expandEnvVars();
  {
    BinaryWriter writer = BinaryWriter(path.string());
    Size count = 50;
    Scalar values[];
    values.resize(count);
    for(Size i=0;i<values.size();i++)
      values[i] = Scalar(i) * 0.7;
    report(values[3]);
    report(values[17]);
    report(values[33]);
  
    writer.write(count.data(), count.dataSize());
    writer.write(values.data(), values.dataSize());
    report('Binary file written.');
  }
  
  if(path.exists())
  {
  
    BinaryReader reader = BinaryReader(path.string());
    Size count = 0;
    reader.read(count.data(), count.dataSize());
    Scalar values[];
    values.resize(count);
    reader.read(values.data(), values.dataSize());
  
    report(values[3]);
    report(values[17]);
    report(values[33]);
  
    report('Binary file read.');
  }
  
}

/*
** Output:

+2.1
+11.9
+23.1
Binary file written.
+2.1
+11.9
+23.1
Binary file read.

*/

Methods

  BinaryReader ( in BinaryReader other )
  BinaryReader ( in String filePath )
  BinaryReader ()
BinaryReader clone ? ()
Boolean close ! ()
Boolean eof ? ()
Boolean isOpen ? ()
Boolean open ! ( in String filePath )
UInt64 pos ? ()
  read ! ( in Data data, in UInt64 dataSize )
  readString ! ( out String string )
  readStringArray ! ( out String strings[] )
  seek ! ( in UInt64 pos )
UInt64 size ? ()
  ~BinaryReader ()

Methods in detail

BinaryReader ( in BinaryReader other )

copy constructor


BinaryReader ( in String filePath )

constructs a new reader object with a given filePath


BinaryReader ()

standard constructor


BinaryReader BinaryReader.clone? ()

clone method


Boolean BinaryReader.close! ()

closes a currently opened file, returns true if successful


Boolean BinaryReader.eof? ()

returns true if the file has reached its end


Boolean BinaryReader.isOpen? ()

returns true if the file is currently open


Boolean BinaryReader.open! ( in String filePath )

opens a new readable file, returns true if successful


UInt64 BinaryReader.pos? ()

tells the position of the stream


BinaryReader.read! ( in Data data, in UInt64 dataSize )

reads a line out of the currently opened file


BinaryReader.readString! ( out String string )

reads a single string from the stream


BinaryReader.readStringArray! ( out String strings[] )

reads an array of strings from the stream


BinaryReader.seek! ( in UInt64 pos )

sets the position of the stream


UInt64 BinaryReader.size? ()

returns the size of the opened file


~ BinaryReader ()

standard destructor