VS:Binary File Operations

From Vectorworks Developer
Jump to navigation Jump to search

.VectorScript|VectorScript ..VS:Function Reference|Function Reference ..VS:Function_Reference_Appendix|Appendix

By Vladislav Stanev

Intro

The existing file functions prior Vectorworks 2018 are now converted to support UTF-8. This means that they will output encoded characters, so working with CHAR becomes harder as CHAR is a single byte interpreted as text, so writing CHAR >= 127 is not possible.

This lead to the addition of the following Vectorworks 2018 function:

  • ReadBin – read the value as binary representation. The string version will ask for encoding and byte count
  • WriteBin – write the value as binary representation. The string version will ask for encoding
  • LenEncoding – return byte count of a string in the specified encoding


PROCEDURE WriteBin( value : CHAR );      { write 1 byte }
PROCEDURE WriteBin( value : BOOLEAN );   { write 1 byte }
PROCEDURE WriteBin( value : REAL );      { write 8 bytes }
PROCEDURE WriteBin( value : INTEGER );   { write 2 bytes }
PROCEDURE WriteBin( value : LONGINT );   { write 4 bytes }
 
PROCEDURE WriteBin( value : STRING; encoding : INTEGER );
                { write sequence of bytes 
                  representing the string in the specified encoding.
                  No terminating 0 is written. }
                { Encoding: 0 – mac; 1 – win; 2 – system; 3 – UTF8; 4 – UTF16}
 
PROCEDURE WriteBin( value : DYNARRAY OF CHAR; encoding : INTEGER  ); {same as STRING}
PROCEDURE ReadBin( VAR value : CHAR );       { read 1 byte }
PROCEDURE ReadBin( VAR value : BOOLEAN );    { read 1 byte }
PROCEDURE ReadBin( VAR value : REAL );       { read 8 bytes }
PROCEDURE ReadBin( VAR value : INTEGER );    { read 2 bytes }
PROCEDURE ReadBin( VAR value : LONGINT );    { read 4 bytes }
 
PROCEDURE ReadBin (VAR  value : STRING; readBytes, encoding : INTEGER );
                { read sequence of bytes requested and return them as a string in the specified encoding. }
                { readBytes can be 0, then the first found zero byte (or bytes in UTF16 encoding) will terminate the string }
{  Encoding: 0 – mac; 1 – win; 2 – system; 3 – UTF8; 4 – UTF16}
 
PROCEDURE ReadBin ( VAR value : DYNARRAY OF CHAR; readBytes, encoding : INTEGER  ); {same as STRING}

These support the ‘:’ formatting similar to the other filing functions. Described in “Data Formatting with Write and WriteLn” in http://developer.vectorworks.net/images/7/72/VectorScriptGuide.pdf

For example: Write( 4 : 1 );

Will write 0x04 as a single byte.