UNPKG

nbt

Version:

A parser and serializer for NBT archives

2,587 lines 26.8 kB
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>JSDoc: Class: Writer</title>

    <script src="scripts/prettify/prettify.js"> </script>
    <script src="scripts/prettify/lang-css.js"> </script>
    <!--[if lt IE 9]>
      <script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <![endif]-->
    <link type="text/css" rel="stylesheet" href="styles/prettify-tomorrow.css">
    <link type="text/css" rel="stylesheet" href="styles/jsdoc-default.css">
</head>

<body>

<div id="main">

    <h1 class="page-title">Class: Writer</h1>

    




<section>

<header>
    
        <h2><span class="attribs"><span class="type-signature"></span></span>
            <span class="ancestors"><a href="module-nbt.html">nbt</a>.</span>Writer<span class="signature">()</span><span class="type-signature"></span></h2>
        
    
</header>

<article>
    <div class="container-overview">
    
        

    

    
    <h4 class="name" id="Writer"><span class="type-signature"></span>new Writer<span class="signature">()</span><span class="type-signature"></span></h4>
    

    



<div class="description">
    In addition to the named writing methods documented below,
the same methods are indexed by the NBT type number as well,
as shown in the example below.
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line162">line 162</a>
    </li></ul></dd>
    

    

    
    <dt class="tag-see">See:</dt>
    <dd class="tag-see">
        <ul>
            <li><a href="module-nbt.Reader.html">module:nbt.Reader</a></li>
        </ul>
    </dd>
    

    
</dl>

















    <h5>Example</h5>
    
    <pre class="prettyprint"><code>var writer = new nbt.Writer();

// all equivalent
writer.int(42);
writer[3](42);
writer(nbt.tagTypes.int)(42);

// overwrite the second int
writer.offset = 0;
writer.int(999);

return writer.buffer;</code></pre>



    
    </div>

    

    

    

    

    

    

    
        <h3 class="subsection-title">Members</h3>

        
            
<h4 class="name" id="offset"><span class="type-signature"></span>offset<span class="type-signature"> :number</span></h4>




<div class="description">
    The location in the buffer where bytes are written or read.
This increases after every write, but can be freely changed.
The buffer will be resized when necessary.
</div>



    <h5>Type:</h5>
    <ul>
        <li>
            
<span class="param-type">number</span>


        </li>
    </ul>





<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line178">line 178</a>
    </li></ul></dd>
    

    

    

    
</dl>






        
    

    
        <h3 class="subsection-title">Methods</h3>

        
            

    

    
    <h4 class="name" id="byte"><span class="type-signature"></span>byte<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">a signed byte</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line225">line 225</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="byteArray"><span class="type-signature"></span>byteArray<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array.&lt;number></span>
|

<span class="param-type">Uint8Array</span>
|

<span class="param-type">Buffer</span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line275">line 275</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="compound"><span class="type-signature"></span>compound<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>

            

            

            <td class="description last">a key/value map
                <h6>Properties</h6>
                

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>KEY</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>

            

            

            <td class="description last">
                <h6>Properties</h6>
                

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>type</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last">the NBT type number</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>

            

            

            <td class="description last">a value matching the type</td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line342">line 342</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    




    <h5>Example</h5>
    
    <pre class="prettyprint"><code>writer.compound({
    foo: { type: 'int', value: 12 },
    bar: { type: 'string', value: 'Hello, World!' }
});</code></pre>



        
            

    

    
    <h4 class="name" id="float"><span class="type-signature"></span>float<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">a signed 64-bit float</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line255">line 255</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="float"><span class="type-signature"></span>float<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">a signed 32-bit float</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line249">line 249</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="getData"><span class="type-signature"></span>getData<span class="signature">()</span><span class="type-signature"> &rarr; {ArrayBuffer}</span></h4>
    

    



<div class="description">
    Returns the writen data as a slice from the internal buffer,
cutting off any padding at the end.
</div>













<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line220">line 220</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    a [0, offset] slice of the interal buffer
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type">ArrayBuffer</span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="int"><span class="type-signature"></span>int<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">a signed 32-bit integer</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line243">line 243</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="intArray"><span class="type-signature"></span>intArray<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array.&lt;number></span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line287">line 287</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="list"><span class="type-signature"></span>list<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Object</span>


            
            </td>

            

            

            <td class="description last">
                <h6>Properties</h6>
                

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>type</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">the NBT type number</td>
        </tr>

    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array</span>


            
            </td>

            

            

            <td class="description last">an array of values</td>
        </tr>

    
    </tbody>
</table>

            </td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line326">line 326</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="long"><span class="type-signature"></span>long<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    



<div class="description">
    As JavaScript does not support 64-bit integers natively, this
method takes an array of two 32-bit integers that make up the
upper and lower halves of the long.
</div>









    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array.&lt;number></span>


            
            </td>

            

            

            <td class="description last">[upper, lower]</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line261">line 261</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="longArray"><span class="type-signature"></span>longArray<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">Array.&lt;number></span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line300">line 300</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="short"><span class="type-signature"></span>short<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">a signed 16-bit integer</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line237">line 237</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="string"><span class="type-signature"></span>string<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">string</span>


            
            </td>

            

            

            <td class="description last"></td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line313">line 313</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
            

    

    
    <h4 class="name" id="ubyte"><span class="type-signature"></span>ubyte<span class="signature">(value)</span><span class="type-signature"> &rarr; {<a href="module-nbt.Writer.html">module:nbt.Writer</a>}</span></h4>
    

    











    <h5>Parameters:</h5>
    

<table class="params">
    <thead>
    <tr>
        
        <th>Name</th>
        

        <th>Type</th>

        

        

        <th class="last">Description</th>
    </tr>
    </thead>

    <tbody>
    

        <tr>
            
                <td class="name"><code>value</code></td>
            

            <td class="type">
            
                
<span class="param-type">number</span>


            
            </td>

            

            

            <td class="description last">an unsigned byte</td>
        </tr>

    
    </tbody>
</table>






<dl class="details">

    

    

    

    

    

    

    

    

    

    

    

    

    
    <dt class="tag-source">Source:</dt>
    <dd class="tag-source"><ul class="dummy"><li>
        <a href="nbt.js.html">nbt.js</a>, <a href="nbt.js.html#line231">line 231</a>
    </li></ul></dd>
    

    

    

    
</dl>













<h5>Returns:</h5>

        
<div class="param-desc">
    itself
</div>



<dl>
    <dt>
        Type
    </dt>
    <dd>
        
<span class="param-type"><a href="module-nbt.Writer.html">module:nbt.Writer</a></span>


    </dd>
</dl>

    





        
    

    

    
</article>

</section>




</div>

<nav>
    <h2><a href="index.html">Home</a></h2><h3>Modules</h3><ul><li><a href="module-nbt.html">nbt</a></li></ul><h3>Classes</h3><ul><li><a href="module-nbt.Reader.html">Reader</a></li><li><a href="module-nbt.Writer.html">Writer</a></li></ul>
</nav>

<br class="clear">

<footer>
    Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 3.5.5</a> on Sun Dec 16 2018 05:05:14 GMT+0100 (CET)
</footer>

<script> prettyPrint(); </script>
<script src="scripts/linenumber.js"> </script>
</body>
</html>