Bytes object

Bytes object

Bytes is an array of bytes.

Constants

N/A

Properties

[index]
integer, element of the array at the index position, read-write index accessor. Zero-based integer index.
length
integer, read-only, number of bytes in the byte vector.
type
any, could be used for any purposes but sciter uses it to report mime-type (string) of the data received or sent by request() method.
name
any, could be used for any purposes but sciter uses it to report file name (string) of the data received or sent by request() method.

Methods

this

( numBytes: integer )

Constructs object of type Bytes – sequence of bytes of numBytes length.

toString

( [encoding:string] ) returns: string

If encoding is not provided or is equal to "base64" then the method returns base64 representation of the byte vector. Otherwise if encoding is one of supported encondings from IANA charset list http://www.iana.org/assignments/character-sets the function returns decoded string.

E.g. var str = bytes.toString("UTF-8"); returns a string from UTF-8 encoded bytes.

fromString

( str: string [, encoding:string] ) returns: Bytes

Static method, constructs Bytes object (byte array)  from string using specified encoding.

If encoding is not specified or is equal to "base64" then base64 encoding is used. Otherwise if encoding is one of supported encondings from IANA charset list http://www.iana.org/assignments/character-sets the function returns encoded bytes.

E.g. var bytes = Bytes.fromString("Привет, мир!", "utf-8"); returns utf-8 encoded bytes of the string.

md5

(  ) returns: string

returns 32 chars string that represents MD-5 digest of the byte array.

crc32

(  ) returns: integer

returns integer that is a result of CRC32 computation of given byte array.

save
( filename:string ) returns: true|false

Saves content of the byte vector into the file. If file exists then it will be overwritten.

load
( filename:string ) returns: Bytes

Static method. Creates new Bytes object, loads file into it and returns that object.