BinaryReader.kl

Types

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.

/*
** 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 ()