You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

79 lines
2.6 KiB

<h1 id="bufferobjects">Buffer objects</h1>
<h2>Overview of buffer types</h2>
<p>Duktape provides the following buffer and buffer-related types:</p>
<table>
<tr>
<th>Type</th>
<th>Standard</th>
<th>Duktape version</th>
<th>Description</th>
</tr>
<tr>
<td>Plain buffer</td>
<td>No<br />Duktape&nbsp;specific</td>
<td>1.0</td>
<td>Plain, primitive buffer value (not an object), similar to how a plain string relates to a String object;
behaves like an ArrayBuffer instance where possible, object coerces to an actual <code>ArrayBuffer</code></td>
</tr>
<tr>
<td>ArrayBuffer object</td>
<td>Yes<br />Khronos/ES6</td>
<td>1.3</td>
<td>Standard object type for representing a byte array</td>
</tr>
<tr>
<td>DataView, typed array objects</td>
<td>Yes<br />Khronos/ES6</td>
<td>1.3</td>
<td>View objects to access an underlying ArrayBuffer</td>
</tr>
<tr>
<td>Node.js Buffer object</td>
<td>No<br />Node.js-like</td>
<td>1.3</td>
<td>Object with <a href="https://nodejs.org/api/buffer.html">Node.js Buffer API</a></td>
</tr>
</table>
<p>See <a href="https://github.com/svaarala/duktape/blob/master/doc/buffers.rst">buffers.rst</a>
for a detailed discussion, including a
<a href="https://github.com/svaarala/duktape/blob/master/doc/buffers.rst#summary-of-buffer-related-values">detailed table of buffer types and their properties</a>.</p>
<h2>Working with buffers</h2>
<p>Buffer values work in both C and Ecmascript code:</p>
<ul>
<li>For Ecmascript code most of the behavior is defined in the relevant API
standards, with exceptions for Duktape-specific features like mixing
different buffer types.</li>
<li>For C code there are API calls to work with
<a href="api.html#taglist-buffer">plain buffers</a> and
<a href="api.html#taglist-bufferobject">buffer objects</a>.</li>
</ul>
<p>See
<a href="http://wiki.duktape.org/HowtoBuffers.html">How to work with buffers</a>
for examples.</p>
<div class="note">
In special cases the plain buffer backing a buffer object may not be large
enough to cover the apparent size of the buffer object; the buffer object
is then "uncovered" or "unbacked". Duktape guarantees memory safe behavior
for such buffers, but other than that behavior varies between calls. For
example, a call may ignore the situation silently returning undefined, NaN,
or zero, or it may throw a TypeError. <b>The behavior for unbacked buffers is
not part of versioning guarantees and may change between minor versions.</b>
</div>
<h2>Current limitations</h2>
<ul>
<li>See <a href="#typedarray-custombehavior">TypedArray binding</a> custom
behavior.</li>
<li>See <a href="#nodejsbuffer-custombehavior">Node.js Buffer binding</a> custom
behavior.</li>
</ul>