Data

Data is not creatable, there's only one instance of it. It can only be accessed through its globally exposed variable.

Data is used to transfer raw pieces of information.
It is possible to access any byte of a Data instance by indexing databyteIndex.

How to read a specific byte of a Data instance?

File:OpenAndReadAll(function(success, result)
  local data = result
  -- get the value of the 5th byte as a number
  local val = data[5]
end)

How to display an image data in a quad? (see [Quad](reference/quad).[Image](reference/quad#property-image) for more options)

File:OpenAndReadAll(function(success, result)
  quad.Image = result
end)

Functions

Data FromBundle ( string filepath )

Opens and returns data of an asset in the app bundle.

-- display the Cubzh logo from the app bundle
quad.Image = {
  data=Data:FromBundle("images/logo.png"),
  alpha=true
}

Reads a byte (represented by an integer between 0 and 255) at current cursor, and advances it.

Reads a Color at current cursor, and advances it.

Reads a double-precision float (represented by a number) at current cursor, and advances it.

Reads a single-precision float (represented by a number) at current cursor, and advances it.

Reads a 16-bits integer (represented by an integer between -32768 and 32767) at current cursor, and advances it.

Reads a 32-bits integer (represented by an integer between -2147483648 and 2147483647) at current cursor, and advances it.

Reads an 8-bits integer (represented by an integer between -128 and 127) at current cursor, and advances it.

Reads an integer at current cursor, and advances it.

Reads a number at current cursor, and advances it.

Reads a Number3 at current cursor, and advances it.

Reads a PhysicsMode at current cursor, and advances it.

Reads a Rotation at current cursor, and advances it.

Reads a string at current cursor, and advances it.

Reads an unsigned 16-bits integer (represented by an integer between 0 and 65535) at current cursor, and advances it.

Reads an unsigned 32-bits integer (represented by an integer between 0 and 4294967295) at current cursor, and advances it.

Reads an unsigned 8-bits integer (represented by an integer between 0 and 255) at current cursor, and advances it.

Returns the data as a string.

File:OpenAndReadAll(function(success, result)
  -- result type is Data
  local data = result
  local str = data:ToString()
  if string.sub(str, 1, 6) == "CUBZH!" then
    print("It's a Cubzh file!")
  end
end)

Returns the data as a table.

nil WriteByte ( integer value )

Writes the given byte (represented by an integer between 0 and 255) at current cursor, and advances it.

nil WriteColor ( Color value )

Writes the given Color at current cursor, and advances it.

Writes the given double-precision float (represented by a number) at current cursor, and advances it.

nil WriteFloat ( number value )

Writes the given single-precision float (represented by a number) at current cursor, and advances it.

Writes the given 16-bits integer (represented by an integer between -32768 and 32767) at current cursor, and advances it.

Writes the given 32-bits integer (represented by an integer between -2147483648 and 2147483647) at current cursor, and advances it.

nil WriteInt8 ( integer value )

Writes the given 8-bits integer (represented by an integer between -128 and 127) at current cursor, and advances it.

Writes the given integer at current cursor, and advances it.

Writes the given number at current cursor, and advances it.

Writes the given Number3 at current cursor, and advances it.

Writes the given PhysicsMode at current cursor, and advances it.

Writes the given Rotation at current cursor, and advances it.

Writes the given string at current cursor, and advances it.

Writes the given unsigned 16-bits integer (represented by an integer between 0 and 65535) at current cursor, and advances it.

Writes the given unsigned 32-bits integer (represented by an integer between 0 and 4294967295) at current cursor, and advances it.

Writes the given unsigned 8-bits integer (represented by an integer between 0 and 255) at current cursor, and advances it.

Properties

Current cursor index inside Data. The cursor advances whenever one of the read/write functions is used. It can also be set directly beforehand.

Number of bytes the Data contains.

HTTP:Get("cu.bzh", function(result)
-- result type is Data
  for i = 1, result.Length do
    -- goes through every byte of the provided Data
  end
end)