Moscrif API Docs for: 2012q3
Show:

Bytes Class

Library: core

Bytes is an array of bytes.

Item Index

Methods

Properties

Methods

this

(
  • numBytes
)
Bytes

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

Parameters:

  • numBytes Integer

    Number of bytes in the byte vector.

Returns:

Bytes: New instance offset Bytes

Example:

var myCars=new Array("Saab", "Volvo", "BMW");

load

(
  • filename
)
Bytes

Create new Bytes object, loads file into it and returns that object.

Parameters:

  • filename String

    Name of file to open. If file does not exist function cause and error.

Returns:

Bytes: Bytes object loaded from file

save

(
  • filename
)

Save content of the byte vector into the file.

Parameters:

  • filename String

    Name of file. If file exists then it will be overwritten.

toHex

() String

Create hexadecimal string from bytes array.

Returns:

String: A hexadecimal representation off the bytes.

Example:

console &lt;&lt; "0x" << bytes.toHex() << "\n";

toString

(
  • [encoding]
)
String

Create string from bytes array. If encoding is not provided then the method returns base64 representation of the byte vector. Otherwise a string from UTF-8 encoded bytes.

Parameters:

Returns:

String: A string from UTF-8 encoded bytes.

Example:

// returns string from UTF-8 encoded bytes
var utf8 = bytes.toString("UTF-8");
// returns base64 representation of the bye vector.
var b64 = bytes.toString();

Properties

[index]

Integer

Element of the array at the index position, read-write index accessor. Zero-based integer index.

length

Integer

Number of bytes in the byte vector.

Example:

var myCars=new Array("Saab", "Volvo", "BMW");
console<<myCars.length<<"\n";  // 3