<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.figuramc.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lexize</id>
	<title>FiguraMC - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.figuramc.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Lexize"/>
	<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php/Special:Contributions/Lexize"/>
	<updated>2026-05-29T17:41:23Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=481</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=481"/>
		<updated>2024-09-29T10:57:35Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In case if buffer state changes after method invocation, new state of example buffer will be displayed below the code snippet.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed()) --&amp;gt; true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Write methods ===&lt;br /&gt;
&lt;br /&gt;
==== write ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;write(value [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeShort ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeShort(value [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeShort(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeUShort ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeUShort(value [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeInt ====&lt;br /&gt;
----&lt;br /&gt;
Writes an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeInt(value [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeInt(2147483647)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeLong ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeLong(value [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeLong(9223372036854775807)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeFloat ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeFloat(value [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeFloat(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeDouble ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeDouble(value [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeDouble(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;40&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;49&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeShortLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeShortLE(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeUShortLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShortLE(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeIntLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeIntLE(2147483647)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeLongLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeLongLE(9223372036854775807)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeFloatLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeFloatLE(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeDoubleLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeDoubleLE(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;49&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;40&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeString ====&lt;br /&gt;
----&lt;br /&gt;
Writes a string in buffer, and returns it&#039;s length in bytes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(value {{type|string}})&amp;lt;/code&amp;gt; || {{type|integer}} || Writes a string in UTF-8 encoding.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(value {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|integer}} || Writes a string in specified encoding.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:writeString(&amp;quot;Hello, world!&amp;quot;)) --&amp;gt; 13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;65&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;2C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;20&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;77&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;72&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;64&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;21&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Decodes Base64 byte array and writes in to buffer. Returns amount of written bytes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeBase64(value {{type|string}})&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:writeBase64(&amp;quot;TWVvdw==&amp;quot;)) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;4D&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;65&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;77&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== writeByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Write a lua string byte array to buffer. Returns amount of written bytes.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeByteArray(value {{type|string}})&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:writeByteArray(&amp;quot;\xAA\xBB\xCC\xDD&amp;quot;)) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Streams ===&lt;br /&gt;
Methods for working with Input and Output streams&lt;br /&gt;
&lt;br /&gt;
==== readFromStream ====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Reads provided stream, and writes it&#039;s data to this buffer. Returns amount of bytes written to buffer.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFromStream(stream {{type|InputStream}})&amp;lt;/code&amp;gt; || {{type|integer}} || Reads provided stream to either max capacity of buffer, or end of stream.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFromStream(stream {{type|InputStream}}, amount {{type|integer}})&amp;lt;/code&amp;gt; || {{type|integer}} || Trying to read specified amount of bytes from provided stream. Resulting amount of read bytes might be less than specified.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opening resource from avatar resources&lt;br /&gt;
local is = resources:get(&amp;quot;buf_read_test.txt&amp;quot;)&lt;br /&gt;
-- Reading content of resource, printing it&#039;s length&lt;br /&gt;
print(buf:readFromStream(is)) --&amp;gt; 13&lt;br /&gt;
-- Resetting buffer position so it can read string from start&lt;br /&gt;
buf:setPosition(0)&lt;br /&gt;
-- Reading string&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;Hello, world!&amp;quot;&lt;br /&gt;
-- Closing input stream&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[ResourcesAPI#get|resources:get]], [[#setPosition|setPosition]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;65&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;2C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;20&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;77&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;72&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;64&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;21&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeToStream ====&lt;br /&gt;
----&lt;br /&gt;
&lt;br /&gt;
Writes bytes from this buffer to provided output stream. Returns amount of bytes written to stream.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeToStream(stream {{type|OutputStream}})&amp;lt;/code&amp;gt; || {{type|integer}} || Writes all available bytes to provided stream.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeToStream(stream {{type|OutputStream}}, amount {{type|integer}})&amp;lt;/code&amp;gt; || {{type|integer}} || Writes specified amount of bytes from current position to provided stream.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opening output stream with FileAPI&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;buf_write_test.txt&amp;quot;)&lt;br /&gt;
-- Preparing future file content&lt;br /&gt;
buf:writeString(&amp;quot;Hello, world!&amp;quot;)&lt;br /&gt;
-- Resetting buffer position, so buffer can write data to stream from start&lt;br /&gt;
buf:setPosition(0)&lt;br /&gt;
-- Writing file data&lt;br /&gt;
buf:writeToStream(os)&lt;br /&gt;
-- Closing output stream&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[FileAPI#openWriteStream|file:openWriteStream]], [[#writeString|writeString]], [[#writeString|setPosition]], [[OutputStream#close|OutputStream:close]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;65&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;2C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;20&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;77&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;72&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;6C&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;64&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;21&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=480</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=480"/>
		<updated>2024-09-29T09:11:28Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Fixed wrong endianess in examples&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In case if buffer state changes after method invocation, new state of example buffer will be displayed below the code snippet.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed()) --&amp;gt; true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Write methods ===&lt;br /&gt;
&lt;br /&gt;
==== write ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;write(value [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeShort ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeShort(value [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeShort(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeUShort ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeUShort(value [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeUShort(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeInt ====&lt;br /&gt;
----&lt;br /&gt;
Writes an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeInt(value [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeInt(2147483647)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeLong ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeLong(value [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeLong(9223372036854775807)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeFloat ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeFloat(value [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeFloat(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeDouble ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeDouble(value [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeDouble(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;40&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;49&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeShortLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeShortLE(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeUShortLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeUShortLE(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeIntLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeIntLE(2147483647)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeLongLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeLongLE(9223372036854775807)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeFloatLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeFloatLE(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeDoubleLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeDoubleLE(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;49&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;40&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=479</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=479"/>
		<updated>2024-09-29T08:59:34Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In case if buffer state changes after method invocation, new state of example buffer will be displayed below the code snippet.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed()) --&amp;gt; true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
=== Write methods ===&lt;br /&gt;
&lt;br /&gt;
==== write ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;write(value [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeShort ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeShort(value [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeShort(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeUShort ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeUShort(value [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeUShort(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeInt ====&lt;br /&gt;
----&lt;br /&gt;
Writes an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeInt(value [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeInt(2147483647)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeLong ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeLong(value [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeLong(9223372036854775807)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeFloat ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeFloat(value [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeFloat(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeDouble ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeDouble(value [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeDouble(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;49&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;40&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeShortLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeShortLE(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeUShortLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeUShortLE(32767)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeIntLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeIntLE(2147483647)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeLongLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeLongLE(9223372036854775807)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;7F&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeFloatLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeFloatLE(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;42&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;48&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== writeDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Writes a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format to this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeDoubleLE(value [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]])&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf::writeDoubleLE(50.0)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;40&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;49&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;00&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=478</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=478"/>
		<updated>2024-09-29T07:16:21Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Replaced the last byte in example buffer with DD (i am so stupid)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In case if buffer state changes after method invocation, new state of example buffer will be displayed below the code snippet.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed()) --&amp;gt; true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;DD&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=477</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=477"/>
		<updated>2024-09-29T07:05:35Z</updated>

		<summary type="html">&lt;p&gt;Lexize: /* isClosed */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In case if buffer state changes after method invocation, new state of example buffer will be displayed below the code snippet.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed()) --&amp;gt; true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=476</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=476"/>
		<updated>2024-09-29T07:03:56Z</updated>

		<summary type="html">&lt;p&gt;Lexize: /* Buffer methods */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
In case if buffer state changes after method invocation, new state of example buffer will be displayed below the code snippet.&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=475</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=475"/>
		<updated>2024-09-29T06:59:34Z</updated>

		<summary type="html">&lt;p&gt;Lexize: /* Supported primitives */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=474</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=474"/>
		<updated>2024-09-29T06:38:15Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
| N&lt;br /&gt;
| A string primitive that can be stored in buffers.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;br /&gt;
&lt;br /&gt;
=== Read methods ===&lt;br /&gt;
&lt;br /&gt;
Methods of buffer related to reading data.&lt;br /&gt;
&lt;br /&gt;
==== read ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 1.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;read()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShort()) --&amp;gt; -21829&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShort ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShort()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShort()) --&amp;gt; 43707&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readInt ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readInt()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readInt()) --&amp;gt; -1430532899&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLong ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLong()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLong()) --&amp;gt; -6144092017057071104&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloat ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloat()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloat()) --&amp;gt; -3.336003e-13&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDouble ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDouble()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDouble()) --&amp;gt; -7.757649e-103&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readShortLE()) --&amp;gt; -17494&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readUShortLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]  in little-endian format from this buffer and moves pointer by 2.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readUShortLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readUShortLE()) --&amp;gt; 48042&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readIntLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads an [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readIntLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readIntLE()) --&amp;gt; -573785174&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readLongLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readLongLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readLongLE()) --&amp;gt; 3721182122&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readFloatLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 4.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readFloatLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readFloatLE()) --&amp;gt; -1.844071e+18&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readDoubleLE ====&lt;br /&gt;
----&lt;br /&gt;
Reads a [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]] in little-endian format from this buffer and moves pointer by 8.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readDoubleLE()&amp;lt;/code&amp;gt; || [[#Supported_primitives|&amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;]]&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readDoubleLE()) --&amp;gt; 1.838508e-314&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
----&lt;br /&gt;
Reads a string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of UTF-8 string.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of UTF-8 string. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(length {{type|integer}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of string with specified encoding. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;ª»ÌÝ&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readBase64 ====&lt;br /&gt;
----&lt;br /&gt;
Reads a Base64 string from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Base64 encoded byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readBase64(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Base64 encoded byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readBase64()) --&amp;gt; &amp;quot;qrvM7g==&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== readByteArray ====&lt;br /&gt;
----&lt;br /&gt;
Reads a byte array from this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray()&amp;lt;/code&amp;gt; || {{type|string}} || Reads all bytes from current buffer position to end of the buffer and returns them in form of Lua string byte array.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readByteArray(length {{type|integer}})&amp;lt;/code&amp;gt; || {{type|string}} || Reads specified amount of bytes from current buffer position and returns them in form of Lua string byte array. If &amp;lt;code&amp;gt;length&amp;lt;/code&amp;gt; is more than available bytes amount, length will be clamped.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:readByteArray()) --&amp;gt; [raw data]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; ||&lt;br /&gt;
|-&lt;br /&gt;
| ||  ||  ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=473</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=473"/>
		<updated>2024-09-29T05:40:21Z</updated>

		<summary type="html">&lt;p&gt;Lexize: /* close */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;uint&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| An unsigned 32 bit length integer. Can contain values in range [0; 4294967295]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ulong&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| An usigned 64 bit length integer. Can contain values in range [0; 18446744073709551615]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2+Length&lt;br /&gt;
| A string primitive that can be stored in buffers. Starts with 1 unsigned short defining the length of the string, and followed with string bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Throws an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=472</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=472"/>
		<updated>2024-09-29T05:37:56Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;uint&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| An unsigned 32 bit length integer. Can contain values in range [0; 4294967295]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ulong&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| An usigned 64 bit length integer. Can contain values in range [0; 18446744073709551615]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2+Length&lt;br /&gt;
| A string primitive that can be stored in buffers. Starts with 1 unsigned short defining the length of the string, and followed with string bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
&lt;br /&gt;
This buffer example is going to be used in all code snippets below:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Buffer variable will be named &amp;lt;code&amp;gt;buf&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== General ===&lt;br /&gt;
General methods of a buffer.&lt;br /&gt;
&lt;br /&gt;
==== getLength ====&lt;br /&gt;
----&lt;br /&gt;
Returns length of this buffer.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;Buffer:getLength()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getLength()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getPosition ====&lt;br /&gt;
----&lt;br /&gt;
Returns current pointer position.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getPosition()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getPosition()) --&amp;gt; 0&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== setPosition ====&lt;br /&gt;
----&lt;br /&gt;
Sets current pointer position. Position will be clamped between &amp;lt;code&amp;gt;0&amp;lt;/code&amp;gt; and current buffer length.&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#getLength|getLength]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;setPosition(position {{type|integer}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:setPosition(2)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| ||  || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt;  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== clear ====&lt;br /&gt;
----&lt;br /&gt;
Clears this buffer and sets it&#039;s pointer position to 0.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;clear()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:clear()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| This buffer is empty, no data to display.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== available ====&lt;br /&gt;
----&lt;br /&gt;
Returns amount of bytes available to read.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;available()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:available()) --&amp;gt; 4&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== getMaxCapacity ====&lt;br /&gt;
----&lt;br /&gt;
Returns max buffer capacity.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;getMaxCapacity()&amp;lt;/code&amp;gt; || {{type|integer}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:getMaxCapacity()) --&amp;gt; 1024000&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
{{note|This is an output for avatars in unmodified Default permissions group}}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== close ====&lt;br /&gt;
----&lt;br /&gt;
Closes this buffer, tells garbage collector to free memory used by it. After closing buffer is unable to use, and any usage attempt will cause an error.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;close()&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
buf:read() --! Thrown an error with message &amp;quot;This byte buffer is closed and cant be used anymore&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
==== isClosed ====&lt;br /&gt;
----&lt;br /&gt;
Checks if this buffer is closed.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isClosed()&amp;lt;/code&amp;gt; || {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:close()&lt;br /&gt;
print(buf:isClosed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#close|close]]&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=471</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=471"/>
		<updated>2024-09-29T03:57:13Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Another fir part 2 (i am sleepy)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;uint&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| An unsigned 32 bit length integer. Can contain values in range [0; 4294967295]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ulong&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| An usigned 64 bit length integer. Can contain values in range [0; 18446744073709551615]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;str&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2+Length&lt;br /&gt;
| A string primitive that can be stored in buffers. Starts with 1 unsigned short defining the length of the string, and followed with string bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
WIP&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=470</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=470"/>
		<updated>2024-09-29T03:54:29Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Another fix&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
== Basics ==&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;uint&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| An unsigned 32 bit length integer. Can contain values in range [0; 4294967295]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ulong&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| An usigned 64 bit length integer. Can contain values in range [0; 18446744073709551615]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2+Length&lt;br /&gt;
| A string primitive that can be stored in buffers. Starts with 1 unsigned short defining the length of the string, and followed with string bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
WIP&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=469</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=469"/>
		<updated>2024-09-29T03:53:35Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Fix&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Basics ==&lt;br /&gt;
&lt;br /&gt;
Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;uint&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| An unsigned 32 bit length integer. Can contain values in range [0; 4294967295]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ulong&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| An usigned 64 bit length integer. Can contain values in range [0; 18446744073709551615]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2+Length&lt;br /&gt;
| A string primitive that can be stored in buffers. Starts with 1 unsigned short defining the length of the string, and followed with string bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
WIP&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=468</id>
		<title>Buffer</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Buffer&amp;diff=468"/>
		<updated>2024-09-29T03:52:28Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Created page with &amp;quot;== Basics ==  Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.  ==== Supported primitives ==== {{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;== Basics ==&lt;br /&gt;
&lt;br /&gt;
Buffer is an utility object that can be created by using &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt;. It is used to get more control of what you are writing and reading, by providing bunch of methods for reading and writing bytes for specific primitive data types.&lt;br /&gt;
&lt;br /&gt;
==== Supported primitives ====&lt;br /&gt;
{{note|On this page methods, instead of standard type names, will often use primitive names from this table for specifying arguments and return types, keep this in mind while reading this page.}}&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Type name !! Size in bytes !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;byte&amp;lt;/code&amp;gt;&lt;br /&gt;
| 1&lt;br /&gt;
| An unsigned 8 bit length integer. Can contain values in range [0; 255]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;short&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| A signed 16 bit length integer. Can contain values in range [-32768; 32767]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ushort&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2&lt;br /&gt;
| An unsigned 16 bit length integer. Can contain values in range [0; 65535]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;int&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A signed 32 bit length integer. Can contain values in range [-2147483648; 2147483647]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;uint&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| An unsigned 32 bit length integer. Can contain values in range [0; 4294967295]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;long&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A signed 64 bit length integer. Can contain values in range [-9223372036854775808; 9223372036854775807]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;ulong&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| An usigned 64 bit length integer. Can contain values in range [0; 18446744073709551615]&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;float&amp;lt;/code&amp;gt;&lt;br /&gt;
| 4&lt;br /&gt;
| A single-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;double&amp;lt;/code&amp;gt;&lt;br /&gt;
| 8&lt;br /&gt;
| A double-precision float-pointing number.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;string&amp;lt;/code&amp;gt;&lt;br /&gt;
| 2+Length&lt;br /&gt;
| A string primitive that can be stored in buffers. Starts with 1 unsigned short defining the length of the string, and followed with string bytes.&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
==== Buffer instantiation and capacity ====&lt;br /&gt;
&lt;br /&gt;
There are two possible ways to instantiate a buffer:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Returns !! Description&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer()&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with initial capacity of 512 bytes.&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;data:createBuffer(capacity {{type|integer}})&amp;lt;/code&amp;gt; || {{type|Buffer}} || Creates a buffer with specified initial capacity.&lt;br /&gt;
|}&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#DataAPI#createBuffer|data:createBuffer]]&lt;br /&gt;
&lt;br /&gt;
Buffer capacity is amount of bytes until buffer will need to reallocate more space. Once it reaches the cap, it reallocates buffer with additional 512 bytes. Buffer can &#039;&#039;&#039;not&#039;&#039;&#039; exceed the amount of allocated memory specified in permissions settings.&lt;br /&gt;
&lt;br /&gt;
==== How buffer works ====&lt;br /&gt;
Buffers have a pointer to current byte in a buffer, and it is moved by read and write methods. Buffers has same pointer both for write and read operations.&lt;br /&gt;
&lt;br /&gt;
For example:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  ||  || &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Right now buffer is pointing to first byte (index 0), so when we do the following:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; 170&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]]&lt;br /&gt;
&lt;br /&gt;
Buffer will be pointing to the next byte:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;BB&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; ||  || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Now when we will write a byte in a buffer:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:write(255)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#write|write]]&lt;br /&gt;
&lt;br /&gt;
It will rewrite the pointed byte, and buffer will be pointing to the next byte.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; || &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Once buffer reaches it&#039;s current end, read methods will act different&lt;br /&gt;
* [[#read|read]] will return -1.&lt;br /&gt;
* Integer and float pointing read methods will read until end, and will fill remaining bytes with nulls.&lt;br /&gt;
* [[#readString|readString]], [[#readByteArray|readByteArray]], and [[#readBase64|readBase64]] will read until end and stop. If pointer is already at end, it will return empty result.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(buf:read()) --&amp;gt; -1&lt;br /&gt;
print(buf:readString()) --&amp;gt; &amp;quot;&amp;quot;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#read|read]], [[#readString|readString]]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
----&lt;br /&gt;
Write methods will add new bytes if buffer is pointing it&#039;s current end, and &#039;&#039;&#039;will&#039;&#039;&#039; move the pointer further:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
buf:writeUShort(65535)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#writeUShort|writeUShort]]&lt;br /&gt;
&lt;br /&gt;
This is how our buffer will look like now:&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;AA&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;CC&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;EE&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt; || &amp;lt;code&amp;gt;FF&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| || || || || || || &amp;lt;code&amp;gt;^^&amp;lt;/code&amp;gt; &lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
== Buffer methods ==&lt;br /&gt;
WIP&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=BufferEncoding&amp;diff=328</id>
		<title>BufferEncoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=BufferEncoding&amp;diff=328"/>
		<updated>2024-09-28T16:44:16Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Encoding !! Alias !! Description&lt;br /&gt;
|-&lt;br /&gt;
|utf8 &lt;br /&gt;
|utf_8&lt;br /&gt;
|[[wikipedia:UTF-8|UTF-8]] encoding&lt;br /&gt;
|-&lt;br /&gt;
|utf16 &lt;br /&gt;
|utf_16&lt;br /&gt;
|[[wikipedia:UTF-16|UTF-16]] encoding&lt;br /&gt;
|-&lt;br /&gt;
|utf16be &lt;br /&gt;
|utf_16_be&lt;br /&gt;
|Big-Endian [[wikipedia:UTF-16|UTF-16]] encoding variant&lt;br /&gt;
|-&lt;br /&gt;
|utf16le &lt;br /&gt;
|utf_16_le&lt;br /&gt;
|Little-Endian [[wikipedia:UTF-16|UTF-16]] encoding variant&lt;br /&gt;
|-&lt;br /&gt;
|ascii&lt;br /&gt;
|&lt;br /&gt;
|[[wikipedia:ASCII|ASCII]] encoding&lt;br /&gt;
|-&lt;br /&gt;
|iso88591 &lt;br /&gt;
|iso_8859_1&lt;br /&gt;
|[[wikipedia:ISO_8859-1|ISO 8859-1]] encoding&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=BufferEncoding&amp;diff=324</id>
		<title>BufferEncoding</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=BufferEncoding&amp;diff=324"/>
		<updated>2024-09-28T16:33:57Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Created page with &amp;quot;{| class=&amp;quot;wikitable&amp;quot; ! Encoding !! Alias |- |utf8  |utf_8 |- |utf16  |utf_16 |- |utf16be  |utf_16_be |- |utf16le  |utf_16_le |- |ascii |- |iso88591  |iso_8859_1 |}&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Encoding !! Alias&lt;br /&gt;
|-&lt;br /&gt;
|utf8 &lt;br /&gt;
|utf_8&lt;br /&gt;
|-&lt;br /&gt;
|utf16 &lt;br /&gt;
|utf_16&lt;br /&gt;
|-&lt;br /&gt;
|utf16be &lt;br /&gt;
|utf_16_be&lt;br /&gt;
|-&lt;br /&gt;
|utf16le &lt;br /&gt;
|utf_16_le&lt;br /&gt;
|-&lt;br /&gt;
|ascii&lt;br /&gt;
|-&lt;br /&gt;
|iso88591 &lt;br /&gt;
|iso_8859_1&lt;br /&gt;
|}&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=318</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=318"/>
		<updated>2024-09-28T16:00:03Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== allowed ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== isPathAllowed ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== exists ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== delete ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory fooBar is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory barFoo has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo doesn&#039;t exist&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== isDirectory ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mkdir ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#exists|exists]]&lt;br /&gt;
&lt;br /&gt;
==== mkdirs ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[#exists|exists]], [[#mkdir|mkdir]]&lt;br /&gt;
&lt;br /&gt;
==== list ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string|[]?}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
printTable(file:list(&amp;quot;&amp;quot;)) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== isFile ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== openReadStream ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[InputStream#close|InputStream:close]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== openWriteStream ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[OutputStream#close|OutputStream:close]]&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string in specified encoding.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== writeString ====&lt;br /&gt;
&lt;br /&gt;
Writes string in specified encoding to file by specified path.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=317</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=317"/>
		<updated>2024-09-28T15:52:56Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== allowed ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== isPathAllowed ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== exists ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== delete ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory fooBar is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory barFoo has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo doesn&#039;t exist&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== isDirectory ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== mkdir ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[FileAPI#exists|exists]]&lt;br /&gt;
&lt;br /&gt;
==== mkdirs ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[FileAPI#exists|exists]], [[FileAPI#mkdir|mkdir]]&lt;br /&gt;
&lt;br /&gt;
==== list ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string|[]?}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
printTable(file:list(&amp;quot;&amp;quot;)) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== isFile ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== openReadStream ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[InputStream#close|InputStream:close]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== openWriteStream ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[OutputStream#close|OutputStream:close]]&lt;br /&gt;
&lt;br /&gt;
==== readString ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string in specified encoding.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== writeString ====&lt;br /&gt;
&lt;br /&gt;
Writes string in specified encoding to file by specified path.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=314</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=314"/>
		<updated>2024-09-28T15:02:21Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory fooBar is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory barFoo has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo doesn&#039;t exist&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[FileAPI#exists|exists]]&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[FileAPI#exists|exists]], [[FileAPI#mkdir|mkdir]]&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string|[]?}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
printTable(file:list(&amp;quot;&amp;quot;)) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isFile&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[InputStream#close|InputStream:close]]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;@see&#039;&#039;&#039; [[OutputStream#close|OutputStream:close]]&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string in specified encoding.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in specified encoding to file by specified path.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=313</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=313"/>
		<updated>2024-09-28T14:48:26Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory fooBar is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory barFoo has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo doesn&#039;t exist&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string|[]?}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
printTable(file:list(&amp;quot;&amp;quot;)) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isFile&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string in specified encoding.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in specified encoding to file by specified path.&lt;br /&gt;
Default encoding is &amp;lt;code&amp;gt;utf8&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|BufferEncoding}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=312</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=312"/>
		<updated>2024-09-28T14:25:20Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory fooBar is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory barFoo has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo doesn&#039;t exist&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string|[]}}&amp;lt;nowiki&amp;gt;|&amp;lt;/nowiki&amp;gt;{{type|nil}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
printTable(file:list(&amp;quot;&amp;quot;)) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isFile&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in file by specified path.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=309</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=309"/>
		<updated>2024-09-28T14:16:07Z</updated>

		<summary type="html">&lt;p&gt;Lexize: /* FileAPI:delete */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory fooBar is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory barFoo has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo doesn&#039;t exist&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}[]?&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local contents = file:list(&amp;quot;&amp;quot;) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isFile&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in file by specified path.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=308</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=308"/>
		<updated>2024-09-28T14:14:46Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory foo is empty&lt;br /&gt;
print(file:delete(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
-- Directory bar has files inside&lt;br /&gt;
print(file:delete(&amp;quot;barFoo&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo is open by some program&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;fooBar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}[]?&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local contents = file:list(&amp;quot;&amp;quot;) --[[{&lt;br /&gt;
&amp;quot;foo.bar&amp;quot;,&lt;br /&gt;
&amp;quot;fooBar&amp;quot;,&lt;br /&gt;
&amp;quot;barFoo&amp;quot;&lt;br /&gt;
}]]&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isFile&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in file by specified path.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=Main_Page&amp;diff=307</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=Main_Page&amp;diff=307"/>
		<updated>2024-09-28T14:00:29Z</updated>

		<summary type="html">&lt;p&gt;Lexize: /* Docs */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Notice&lt;br /&gt;
 |content=[https://figura-wiki.pages.dev &amp;lt;big&amp;gt;&#039;&#039;&#039;Looking for the old wiki? Click Here&#039;&#039;&#039;&amp;lt;/big&amp;gt;]&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
==Docs==&lt;br /&gt;
* [[ModelPart]]&lt;br /&gt;
* [[Events]]&lt;br /&gt;
* [[Event]]&lt;br /&gt;
* [[ConfigAPI]]&lt;br /&gt;
* [[Colors]]&lt;br /&gt;
* [[FileAPI]]&lt;br /&gt;
&lt;br /&gt;
==Tutorials==&lt;br /&gt;
* [[Pings (Tutorial)]]&lt;br /&gt;
* [[Blockbench]]&lt;br /&gt;
* [[Blinking]]&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=306</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=306"/>
		<updated>2024-09-28T13:57:21Z</updated>

		<summary type="html">&lt;p&gt;Lexize: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory foo is empty&lt;br /&gt;
print(file:delete(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Directory bar has files inside&lt;br /&gt;
print(file:delete(&amp;quot;bar&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo is open by some program&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;foo&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}[]?&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local contents = file:list(&amp;quot;path/to/dir&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isFile&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isFile(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isFile(&amp;quot;foo.bar&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in file by specified path.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
	<entry>
		<id>https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=305</id>
		<title>FileAPI</title>
		<link rel="alternate" type="text/html" href="https://wiki.figuramc.org/index.php?title=FileAPI&amp;diff=305"/>
		<updated>2024-09-28T13:55:13Z</updated>

		<summary type="html">&lt;p&gt;Lexize: Created page with &amp;quot;{{Host only|kind=API}}  &amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.  FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.  == Security == FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&amp;#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder wi...&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{Host only|kind=API}}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;code&amp;gt;FileAPI&amp;lt;/code&amp;gt; allows your avatar to access files in isolated folder.&lt;br /&gt;
&lt;br /&gt;
FileAPI is available as global &amp;lt;code&amp;gt;file&amp;lt;/code&amp;gt; variable.&lt;br /&gt;
&lt;br /&gt;
== Security ==&lt;br /&gt;
FileAPI is fully isolated in your data folder. It is located in your Figura folder, so, default path for it would be &amp;lt;code&amp;gt;figura/data&amp;lt;/code&amp;gt;. FileAPI can&#039;t access any files or directories out of this folder, even when using symbolic links. Attempt to access file or directory outside data folder will result in error.&lt;br /&gt;
Every used path in methods is relative to data folder.&lt;br /&gt;
&lt;br /&gt;
== FileAPI methods ==&lt;br /&gt;
&lt;br /&gt;
=== Security checks ===&lt;br /&gt;
&lt;br /&gt;
Security related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:allowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if FileAPI usage is allowed for this avatar.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;allowed()&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Prints false on non-host avatar.&lt;br /&gt;
print(file:allowed())&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isPathAllowed&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if path is allowed for usage.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isPathAllowed(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Relative paths are always relative to data folder.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Relative paths that are pointing outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;../foo&amp;quot;)) -- false&lt;br /&gt;
-- Absolute paths pointing to figura data folder are also allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/path/to/figura/data/foo&amp;quot;)) -- true&lt;br /&gt;
-- Absolute paths outside of data folder are not allowed.&lt;br /&gt;
print(file:isPathAllowed(&amp;quot;C:/foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Common ===&lt;br /&gt;
&lt;br /&gt;
Methods related both to files and directories.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:exists&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path exists.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;exists(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:delete&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Deletes file or directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;delete(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Directory foo is empty&lt;br /&gt;
print(file:delete(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
-- Directory bar has files inside&lt;br /&gt;
print(file:delete(&amp;quot;bar&amp;quot;)) -- false&lt;br /&gt;
-- foo.bar is not open by any program&lt;br /&gt;
print(file:delete(&amp;quot;foo.bar&amp;quot;)) -- true&lt;br /&gt;
-- bar.foo is open by some program&lt;br /&gt;
print(file:delete(&amp;quot;bar.foo&amp;quot;)) -- false&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Directories ===&lt;br /&gt;
&lt;br /&gt;
Directory related methods of FileAPI.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:isDirectory&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Checks if specified path is directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;isDirectory(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:isDirectory(&amp;quot;foo&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdir&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:mkdirs&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Creates directory by specified path, and all parent directories if they doesn&#039;t exist. Returns true if successful.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;mkdir(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|boolean}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdir(&amp;quot;foo/bar&amp;quot;)) -- false&lt;br /&gt;
print(file:mkdirs(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
print(file:exists(&amp;quot;foo/bar&amp;quot;)) -- true&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:list&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Lists files and directories by specified path. Returns table with paths, or null if path doesn&#039;t exist or not a directory.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;list(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}[]?&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
local contents = file:list(&amp;quot;path/to/dir&amp;quot;)&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== Files ===&lt;br /&gt;
Methods related to files.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openReadStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open input stream for file at specified path. Throws an error if file doesn&#039;t exist.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openReadStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|InputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an input stream.&lt;br /&gt;
local is = file:openReadStream(&amp;quot;foo.bar&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
is:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:openWriteStream&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Open output stream for file at specified path. Throws an error if unable to create a file.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;openWriteStream(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|OutputStream}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
-- Opens an output stream.&lt;br /&gt;
local os = file:openWriteStream(&amp;quot;bar.foo&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
-- Stream must be closed when you finished working with it.&lt;br /&gt;
os:close()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:readString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Reads file at specified path and returns it&#039;s contents as a string.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments !! Return Type&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;readString(path {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
| {{type|string}}&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:readString(&amp;quot;foo.bar&amp;quot;)) -- Hello, world!&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;code&amp;gt;FileAPI:writeString&amp;lt;/code&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
Writes string in file by specified path.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Arguments&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| &amp;lt;code&amp;gt;writeString(path {{type|string}}, contents {{type|string}}, encoding {{type|string}})&amp;lt;/code&amp;gt;&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;lua&amp;quot;&amp;gt;&lt;br /&gt;
print(file:writeString(&amp;quot;foo.bar&amp;quot;, &amp;quot;Hello, world!&amp;quot;))&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;</summary>
		<author><name>Lexize</name></author>
	</entry>
</feed>