ByteStream
Object represents stream of bytes
Instance attributes
- eos: bool
-
Indicates, if current position is in the end of byte stream
- pos: int
-
Current position in the byte stream
- size: int
-
Size of byte stream in bytes
Instance methods
- seek(position, origin=SeekOrigin::Begin): int
-
Change current position in byte stream.
Table 1. Parameters position
Integer
Offset to seek to, relative to
originorigin
Integer
Optional. Reference position, one of the SeekOrigin constants. Defaults to
SeekOrigin::Begin.ReturnActual position if position change was successful or
-1if position change was not successful.
- readByte(): int (32 bit)
-
Read byte from byte stream and return it’s value. Returns
0if current position is at the end of the stream.
- readInt16B(): int (32 bit)
-
Read big-endian 16-bit signed integer from byte stream and return it’s value.
- readInt32B(): int (32 bit)
-
Read big-endian 32-bit signed integer from byte stream and return it’s value.
- readInt64B(): int (64 bit)
-
Read big-endian 64-bit signed integer from byte stream and return it’s value.
- readUInt16B(): int (32 bit)
-
Read big-endian 16-bit unsigned integer from byte stream and return it’s value.
- readUInt32B(): int (32 bit)
-
Read big-endian 32-bit unsigned integer from byte stream and return it’s value.
- readUInt64B(): int (64 bit)
-
Read big-endian 64-bit unsigned integer from byte stream and return it’s value.
- readFloatB(): floating-point number
-
Read 8 bytes from stream as big-endian floating-point number and return it’s value. Deprecated from v 5.1.2, readFloat64B should be used instead.
- readFloat32B(): floating-point number (32 bit)
-
Read 4 bytes from stream as big-endian floating-point number and return it’s value.
- readFloat64B(): floating-point number (64 bit)
-
Read 8 bytes from stream as big-endian floating-point number and return it’s value.
- readInt16L(): int (32 bit)
-
Read little-endian 16-bit signed integer from byte stream and return it’s value.
- readInt32L(): int (32 bit)
-
Read little-endian 32-bit signed integer from byte stream and return it’s value.
- readInt64L(): int (64 bit)
-
Read little-endian 64-bit signed integer from byte stream and return it’s value.
- readUInt16L(): int (32 bit)
-
Read little-endian 16-bit unsigned integer from byte stream and return it’s value.
- readUInt32L(): int (32 bit)
-
Read little-endian 32-bit unsigned integer from byte stream and return it’s value.
- readUInt64L(): int (64 bit)
-
Read little-endian 64-bit unsigned integer from byte stream and return it’s value.
- readFloatL(): floating-point number
-
Read 8 bytes from stream as little-endian floating-point number and return it’s value. Deprecated from v 5.1.2, readFloat64L should be used instead.
- readFloat32L(): floating-point number (32 bit)
-
Read 4 bytes from stream as little-endian floating-point number and return it’s value.
- readFloat64L(): floating-point number (64 bit)
-
Read 8 bytes from stream as little-endian floating-point number and return it’s value.
- readCString(codepage): String
-
Read C-string from stream and return it’s value. It’s expected that string in the stream is terminated by a null character.
Table 2. Parameters codepage
String
Optional. Code page of the string in the stream, for example
UTF-8,ASCII,UCS-2orUCS-4. System default code page is used if omitted.ReturnString value, or
nullif the stream contains no terminating null character or the string cannot be decoded.
- readPString(codepage): String
-
Read length-prefixed string from stream and return it’s value. The string in the stream must be preceded by its length in bytes as a big-endian number: 2 bytes, or 4 bytes if the highest bit of the first byte is set (the format written by
writePString()).Table 3. Parameters codepage
String
Optional. Code page of the string in the stream, for example
UTF-8,ASCII,UCS-2orUCS-4. System default code page is used if omitted.ReturnString value, or
nullif the stream does not contain the whole string or the string cannot be decoded.
- readString(length, codepage): String
-
Read string from stream and return it’s value.
Table 4. Parameters length
Integer
Length of the string in bytes
codepage
String
Optional. Code page of the string in the stream, for example
UTF-8,ASCII,UCS-2orUCS-4. System default code page is used if omitted.ReturnString value, or
nullif the stream has fewer thanlengthbytes left or the string cannot be decoded.
- writeByte(value): void
-
Write provided value as byte to the byte stream at current position.
- writeInt16B(value): void
-
Write provided value to the byte stream as big-endian 16-bit integer .
- writeInt32B(value): void
-
Write provided value to the byte stream as big-endian 32-bit integer.
- writeInt64B(value): void
-
Write provided value to the byte stream as big-endian 64-bit integer.
- writeFloatB(value): void
-
Write provided value to the byte stream as big-endian 64-bit float. Deprecated from v 5.1.2, writeFloat64B should be used instead. Value must be a floating-point number; passing an integer causes a runtime error.
- writeFloat32B(value): void
-
Write provided value to the byte stream as big-endian 32-bit float. Value must be a floating-point number; passing an integer causes a runtime error.
- writeFloat64B(value): void
-
Write provided value to the byte stream as big-endian 64-bit float. Value must be a floating-point number; passing an integer causes a runtime error.
- writeInt16L(value): void
-
Write provided value to the byte stream as little-endian 16-bit integer.
- writeInt32L(value): void
-
Write provided value to the byte stream as little-endian 32-bit integer.
- writeInt64L(value): void
-
Write provided value to the byte stream as little-endian 64-bit integer.
- writeFloatL(value): void
-
Write provided value to the byte stream as little-endian 64-bit float. Deprecated from v 5.1.2, writeFloat64L should be used instead. Value must be a floating-point number; passing an integer causes a runtime error.
- writeFloat32L(value): void
-
Write provided value to the byte stream as little-endian 32-bit float. Value must be a floating-point number; passing an integer causes a runtime error.
- writeFloat64L(value): void
-
Write provided value to the byte stream as little-endian 64-bit float. Value must be a floating-point number; passing an integer causes a runtime error.
- writeCString(string, codepage): int
-
Write provided string to the byte stream as null-terminated string (C-string).
Table 5. Parameters string
String
String to write
codepage
String
Optional. Code page to encode the string with, for example
UTF-8,ASCII,UCS-2orUCS-4. System default code page is used if omitted.ReturnNumber of bytes written.
- writePString(string, codepage): int
-
Write provided string to the byte stream, preceded by its length in bytes (2-byte big-endian number, or 4 bytes with the highest bit set for long strings). Use
readPString()to read it back.Table 6. Parameters string
String
String to write
codepage
String
Optional. Code page to encode the string with, for example
UTF-8,ASCII,UCS-2orUCS-4. System default code page is used if omitted.ReturnNumber of bytes written.
- writeString(string, codepage): int
-
Write provided string to the byte stream.
Table 7. Parameters string
String
String to write
codepage
String
Optional. Code page to encode the string with, for example
UTF-8,ASCII,UCS-2orUCS-4. System default code page is used if omitted.ReturnNumber of bytes written.