UNPKG

wombo-dream-api

Version:
127 lines 80.4 kB
<!DOCTYPE html><html class="default"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>BufferConstructor | wombo-dream-api</title><meta name="description" content="Documentation for wombo-dream-api"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="../assets/style.css"/><link rel="stylesheet" href="../assets/highlight.css"/><script async src="../assets/search.js" id="search-script"></script></head><body><script>document.body.classList.add(localStorage.getItem("tsd-theme") || "os")</script><header><div class="tsd-page-toolbar"><div class="container"><div class="table-wrap"><div class="table-cell" id="tsd-search" data-base=".."><div class="field"><label for="tsd-search-field" class="tsd-widget search no-caption">Search</label><input type="text" id="tsd-search-field"/></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="../index.html" class="title">wombo-dream-api</a></div><div class="table-cell" id="tsd-widgets"><div id="tsd-filter"><a href="#" class="tsd-widget options no-caption" data-toggle="options">Options</a><div class="tsd-filter-group"><div class="tsd-select" id="tsd-filter-visibility"><span class="tsd-select-label">All</span><ul class="tsd-select-list"><li data-value="public">Public</li><li data-value="protected">Public/Protected</li><li data-value="private" class="selected">All</li></ul></div> <input type="checkbox" id="tsd-filter-inherited" checked/><label class="tsd-widget" for="tsd-filter-inherited">Inherited</label><input type="checkbox" id="tsd-filter-externals" checked/><label class="tsd-widget" for="tsd-filter-externals">Externals</label></div></div><a href="#" class="tsd-widget menu no-caption" data-toggle="menu">Menu</a></div></div></div></div><div class="tsd-page-title"><div class="container"><ul class="tsd-breadcrumb"><li><a href="../modules.html">wombo-dream-api</a></li><li><a href="../modules/_internal_.html">&lt;internal&gt;</a></li><li><a href="_internal_.BufferConstructor.html">BufferConstructor</a></li></ul><h1>Interface BufferConstructor</h1></div></div></header><div class="container container-main"><div class="row"><div class="col-8 col-content"><section class="tsd-panel tsd-comment"><div class="tsd-comment tsd-typography"><div class="lead"> <p>Raw data is stored in instances of the Buffer class. A Buffer is similar to an array of integers but corresponds to a raw memory allocation outside the V8 heap. A Buffer cannot be resized. Valid string encodings: &#39;ascii&#39;|&#39;utf8&#39;|&#39;utf16le&#39;|&#39;ucs2&#39;(alias of &#39;utf16le&#39;)|&#39;base64&#39;|&#39;base64url&#39;|&#39;binary&#39;(deprecated)|&#39;hex&#39;</p> </div></div></section><section class="tsd-panel tsd-hierarchy"><h3>Hierarchy</h3><ul class="tsd-hierarchy"><li><span class="target">BufferConstructor</span></li></ul></section><section class="tsd-panel-group tsd-index-group"><h2>Index</h2><section class="tsd-panel tsd-index-panel"><div class="tsd-index-content"><section class="tsd-index-section tsd-is-external"><h3>Constructors</h3><ul class="tsd-index-list"><li class="tsd-kind-constructor tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#constructor" class="tsd-kind-icon">constructor</a></li></ul></section><section class="tsd-index-section tsd-is-external"><h3>Properties</h3><ul class="tsd-index-list"><li class="tsd-kind-property tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#poolSize" class="tsd-kind-icon">pool<wbr/>Size</a></li></ul></section><section class="tsd-index-section tsd-is-external"><h3>Methods</h3><ul class="tsd-index-list"><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#alloc" class="tsd-kind-icon">alloc</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#allocUnsafe" class="tsd-kind-icon">alloc<wbr/>Unsafe</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#allocUnsafeSlow" class="tsd-kind-icon">alloc<wbr/>Unsafe<wbr/>Slow</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#byteLength" class="tsd-kind-icon">byte<wbr/>Length</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#compare" class="tsd-kind-icon">compare</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#concat" class="tsd-kind-icon">concat</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#from" class="tsd-kind-icon">from</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#isBuffer" class="tsd-kind-icon">is<wbr/>Buffer</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#isEncoding" class="tsd-kind-icon">is<wbr/>Encoding</a></li><li class="tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a href="_internal_.BufferConstructor.html#of" class="tsd-kind-icon">of</a></li></ul></section></div></section></section><section class="tsd-panel-group tsd-member-group tsd-is-external"><h2>Constructors</h2><section class="tsd-panel tsd-member tsd-kind-constructor tsd-parent-kind-interface tsd-is-external"><a id="constructor" class="tsd-anchor"></a><h3 class="tsd-anchor-link">constructor<a href="#constructor" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-constructor tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">new <wbr/>Buffer<wbr/>Constructor<span class="tsd-signature-symbol">(</span>str<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span>, encoding<span class="tsd-signature-symbol">?: </span><a href="../modules/_internal_.html#BufferEncoding" class="tsd-signature-type" data-tsd-kind="Type alias">BufferEncoding</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li><li class="tsd-signature tsd-kind-icon">new <wbr/>Buffer<wbr/>Constructor<span class="tsd-signature-symbol">(</span>size<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li><li class="tsd-signature tsd-kind-icon">new <wbr/>Buffer<wbr/>Constructor<span class="tsd-signature-symbol">(</span>array<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Uint8Array</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li><li class="tsd-signature tsd-kind-icon">new <wbr/>Buffer<wbr/>Constructor<span class="tsd-signature-symbol">(</span>arrayBuffer<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">ArrayBuffer</span><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#SharedArrayBuffer-1" class="tsd-signature-type" data-tsd-kind="Variable">SharedArrayBuffer</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li><li class="tsd-signature tsd-kind-icon">new <wbr/>Buffer<wbr/>Constructor<span class="tsd-signature-symbol">(</span>array<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">readonly </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li><li class="tsd-signature tsd-kind-icon">new <wbr/>Buffer<wbr/>Constructor<span class="tsd-signature-symbol">(</span>buffer<span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:189</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new buffer containing the given {str}.</p> </div><dl class="tsd-comment-tags"><dt>deprecated</dt><dd><p>since v10.0.0 - Use <code>Buffer.from(string[, encoding])</code> instead.</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>str: <span class="tsd-signature-type">string</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>String to store in buffer.</p> </div></div></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> encoding: <a href="../modules/_internal_.html#BufferEncoding" class="tsd-signature-type" data-tsd-kind="Type alias">BufferEncoding</a></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>encoding to use, optional. Default is &#39;utf8&#39;</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:196</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new buffer of {size} octets.</p> </div><dl class="tsd-comment-tags"><dt>deprecated</dt><dd><p>since v10.0.0 - Use <code>Buffer.alloc()</code> instead (also see <code>Buffer.allocUnsafe()</code>).</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>size: <span class="tsd-signature-type">number</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>count of octets to allocate.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:203</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new buffer containing the given {array} of octets.</p> </div><dl class="tsd-comment-tags"><dt>deprecated</dt><dd><p>since v10.0.0 - Use <code>Buffer.from(array)</code> instead.</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>array: <span class="tsd-signature-type">Uint8Array</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The octets to store.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:212</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Produces a Buffer backed by the same allocated memory as the given {ArrayBuffer}/{SharedArrayBuffer}.</p> </div><dl class="tsd-comment-tags"><dt>deprecated</dt><dd><p>since v10.0.0 - Use <code>Buffer.from(arrayBuffer[, byteOffset[, length]])</code> instead.</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>arrayBuffer: <span class="tsd-signature-type">ArrayBuffer</span><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#SharedArrayBuffer-1" class="tsd-signature-type" data-tsd-kind="Variable">SharedArrayBuffer</a></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The ArrayBuffer with which to share memory.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:219</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new buffer containing the given {array} of octets.</p> </div><dl class="tsd-comment-tags"><dt>deprecated</dt><dd><p>since v10.0.0 - Use <code>Buffer.from(array)</code> instead.</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>array: <span class="tsd-signature-symbol">readonly </span><span class="tsd-signature-type">any</span><span class="tsd-signature-symbol">[]</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The octets to store.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:226</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Copies the passed {buffer} data onto a new {Buffer} instance.</p> </div><dl class="tsd-comment-tags"><dt>deprecated</dt><dd><p>since v10.0.0 - Use <code>Buffer.from(buffer)</code> instead.</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>buffer: <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The buffer to copy.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li></ul></section></section><section class="tsd-panel-group tsd-member-group tsd-is-external"><h2>Properties</h2><section class="tsd-panel tsd-member tsd-kind-property tsd-parent-kind-interface tsd-is-external"><a id="poolSize" class="tsd-anchor"></a><h3 class="tsd-anchor-link">pool<wbr/>Size<a href="#poolSize" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><div class="tsd-signature tsd-kind-icon">pool<wbr/>Size<span class="tsd-signature-symbol">:</span> <span class="tsd-signature-type">number</span></div><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:529</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>This is the size (in bytes) of pre-allocated internal <code>Buffer</code> instances used for pooling. This value may be modified.</p> </div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.11.3</p> </dd></dl></div></section></section><section class="tsd-panel-group tsd-member-group tsd-is-external"><h2>Methods</h2><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a id="alloc" class="tsd-anchor"></a><h3 class="tsd-anchor-link">alloc<a href="#alloc" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">alloc<span class="tsd-signature-symbol">(</span>size<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span>, fill<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a>, encoding<span class="tsd-signature-symbol">?: </span><a href="../modules/_internal_.html#BufferEncoding" class="tsd-signature-type" data-tsd-kind="Type alias">BufferEncoding</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:441</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>fill</code> is <code>undefined</code>, the<code>Buffer</code> will be zero-filled.</p> </div><div><pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">buf</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">alloc</span><span class="hl-1">(</span><span class="hl-9">5</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-0">buf</span><span class="hl-1">);</span><br/><span class="hl-7">// Prints: &lt;Buffer 00 00 00 00 00&gt;</span> </code></pre> <p>If <code>size</code> is larger than {@link constants.MAX_LENGTH} or smaller than 0, <code>ERR_INVALID_ARG_VALUE</code> is thrown.</p> <p>If <code>fill</code> is specified, the allocated <code>Buffer</code> will be initialized by calling <code>buf.fill(fill)</code>.</p> <pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">buf</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">alloc</span><span class="hl-1">(</span><span class="hl-9">5</span><span class="hl-1">, </span><span class="hl-5">&#39;a&#39;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-0">buf</span><span class="hl-1">);</span><br/><span class="hl-7">// Prints: &lt;Buffer 61 61 61 61 61&gt;</span> </code></pre> <p>If both <code>fill</code> and <code>encoding</code> are specified, the allocated <code>Buffer</code> will be initialized by calling <code>buf.fill(fill, encoding)</code>.</p> <pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">buf</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">alloc</span><span class="hl-1">(</span><span class="hl-9">11</span><span class="hl-1">, </span><span class="hl-5">&#39;aGVsbG8gd29ybGQ=&#39;</span><span class="hl-1">, </span><span class="hl-5">&#39;base64&#39;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-0">buf</span><span class="hl-1">);</span><br/><span class="hl-7">// Prints: &lt;Buffer 68 65 6c 6c 6f 20 77 6f 72 6c 64&gt;</span> </code></pre> <p>Calling <code>Buffer.alloc()</code> can be measurably slower than the alternative <code>Buffer.allocUnsafe()</code> but ensures that the newly created <code>Buffer</code> instance contents will never contain sensitive data from previous allocations, including data that might not have been allocated for <code>Buffer</code>s.</p> <p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p> </div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v5.10.0</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>size: <span class="tsd-signature-type">number</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The desired length of the new <code>Buffer</code>.</p> </div></div></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> fill: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h5></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> encoding: <a href="../modules/_internal_.html#BufferEncoding" class="tsd-signature-type" data-tsd-kind="Type alias">BufferEncoding</a></h5></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a id="allocUnsafe" class="tsd-anchor"></a><h3 class="tsd-anchor-link">alloc<wbr/>Unsafe<a href="#allocUnsafe" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">alloc<wbr/>Unsafe<span class="tsd-signature-symbol">(</span>size<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:478</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than {@link constants.MAX_LENGTH} or smaller than 0, <code>ERR_INVALID_ARG_VALUE</code> is thrown.</p> </div><div><p>The underlying memory for <code>Buffer</code> instances created in this way is <em>not</em> <em>initialized</em>. The contents of the newly created <code>Buffer</code> are unknown and_may contain sensitive data_. Use <code>Buffer.alloc()</code> instead to initialize<code>Buffer</code> instances with zeroes.</p> <pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">buf</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">allocUnsafe</span><span class="hl-1">(</span><span class="hl-9">10</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-0">buf</span><span class="hl-1">);</span><br/><span class="hl-7">// Prints (contents may vary): &lt;Buffer a0 8b 28 3f 01 00 00 00 50 32&gt;</span><br/><br/><span class="hl-0">buf</span><span class="hl-1">.</span><span class="hl-4">fill</span><span class="hl-1">(</span><span class="hl-9">0</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-0">buf</span><span class="hl-1">);</span><br/><span class="hl-7">// Prints: &lt;Buffer 00 00 00 00 00 00 00 00 00 00&gt;</span> </code></pre> <p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p> <p>The <code>Buffer</code> module pre-allocates an internal <code>Buffer</code> instance of size <code>Buffer.poolSize</code> that is used as a pool for the fast allocation of new<code>Buffer</code> instances created using <code>Buffer.allocUnsafe()</code>,<code>Buffer.from(array)</code>, <code>Buffer.concat()</code>, and the deprecated<code>new Buffer(size)</code> constructor only when <code>size</code> is less than or equal to <code>Buffer.poolSize &gt;&gt; 1</code> (floor of <code>Buffer.poolSize</code> divided by two).</p> <p>Use of this pre-allocated internal memory pool is a key difference between calling <code>Buffer.alloc(size, fill)</code> vs. <code>Buffer.allocUnsafe(size).fill(fill)</code>. Specifically, <code>Buffer.alloc(size, fill)</code> will <em>never</em> use the internal <code>Buffer</code>pool, while <code>Buffer.allocUnsafe(size).fill(fill)</code><em>will</em> use the internal<code>Buffer</code> pool if <code>size</code> is less than or equal to half <code>Buffer.poolSize</code>. The difference is subtle but can be important when an application requires the additional performance that <code>Buffer.allocUnsafe()</code> provides.</p> </div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v5.10.0</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>size: <span class="tsd-signature-type">number</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The desired length of the new <code>Buffer</code>.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a id="allocUnsafeSlow" class="tsd-anchor"></a><h3 class="tsd-anchor-link">alloc<wbr/>Unsafe<wbr/>Slow<a href="#allocUnsafeSlow" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">alloc<wbr/>Unsafe<wbr/>Slow<span class="tsd-signature-symbol">(</span>size<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:523</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Allocates a new <code>Buffer</code> of <code>size</code> bytes. If <code>size</code> is larger than {@link constants.MAX_LENGTH} or smaller than 0, <code>ERR_INVALID_ARG_VALUE</code> is thrown. A zero-length <code>Buffer</code> is created if <code>size</code> is 0.</p> </div><div><p>The underlying memory for <code>Buffer</code> instances created in this way is <em>not</em> <em>initialized</em>. The contents of the newly created <code>Buffer</code> are unknown and_may contain sensitive data_. Use <code>buf.fill(0)</code> to initialize such <code>Buffer</code> instances with zeroes.</p> <p>When using <code>Buffer.allocUnsafe()</code> to allocate new <code>Buffer</code> instances, allocations under 4 KB are sliced from a single pre-allocated <code>Buffer</code>. This allows applications to avoid the garbage collection overhead of creating many individually allocated <code>Buffer</code> instances. This approach improves both performance and memory usage by eliminating the need to track and clean up as many individual <code>ArrayBuffer</code> objects.</p> <p>However, in the case where a developer may need to retain a small chunk of memory from a pool for an indeterminate amount of time, it may be appropriate to create an un-pooled <code>Buffer</code> instance using <code>Buffer.allocUnsafeSlow()</code> and then copying out the relevant bits.</p> <pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-7">// Need to keep around a few small chunks of memory.</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">store</span><span class="hl-1"> = [];</span><br/><br/><span class="hl-0">socket</span><span class="hl-1">.</span><span class="hl-4">on</span><span class="hl-1">(</span><span class="hl-5">&#39;readable&#39;</span><span class="hl-1">, () </span><span class="hl-2">=&gt;</span><span class="hl-1"> {</span><br/><span class="hl-1"> </span><span class="hl-2">let</span><span class="hl-1"> </span><span class="hl-0">data</span><span class="hl-1">;</span><br/><span class="hl-1"> </span><span class="hl-6">while</span><span class="hl-1"> (</span><span class="hl-2">null</span><span class="hl-1"> !== (</span><span class="hl-0">data</span><span class="hl-1"> = </span><span class="hl-0">readable</span><span class="hl-1">.</span><span class="hl-4">read</span><span class="hl-1">())) {</span><br/><span class="hl-1"> </span><span class="hl-7">// Allocate for retained data.</span><br/><span class="hl-1"> </span><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">sb</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">allocUnsafeSlow</span><span class="hl-1">(</span><span class="hl-9">10</span><span class="hl-1">);</span><br/><br/><span class="hl-1"> </span><span class="hl-7">// Copy the data into the new allocation.</span><br/><span class="hl-1"> </span><span class="hl-0">data</span><span class="hl-1">.</span><span class="hl-4">copy</span><span class="hl-1">(</span><span class="hl-0">sb</span><span class="hl-1">, </span><span class="hl-9">0</span><span class="hl-1">, </span><span class="hl-9">0</span><span class="hl-1">, </span><span class="hl-9">10</span><span class="hl-1">);</span><br/><br/><span class="hl-1"> </span><span class="hl-0">store</span><span class="hl-1">.</span><span class="hl-4">push</span><span class="hl-1">(</span><span class="hl-0">sb</span><span class="hl-1">);</span><br/><span class="hl-1"> }</span><br/><span class="hl-1">});</span> </code></pre> <p>A <code>TypeError</code> will be thrown if <code>size</code> is not a number.</p> </div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v5.12.0</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>size: <span class="tsd-signature-type">number</span></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>The desired length of the new <code>Buffer</code>.</p> </div></div></li></ul><h4 class="tsd-returns-title">Returns <a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></h4></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a id="byteLength" class="tsd-anchor"></a><h3 class="tsd-anchor-link">byte<wbr/>Length<a href="#byteLength" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">byte<wbr/>Length<span class="tsd-signature-symbol">(</span>string<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">ArrayBuffer</span><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#SharedArrayBuffer-1" class="tsd-signature-type" data-tsd-kind="Variable">SharedArrayBuffer</a><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html#ArrayBufferView" class="tsd-signature-type" data-tsd-kind="Type alias">ArrayBufferView</a>, encoding<span class="tsd-signature-symbol">?: </span><a href="../modules/_internal_.html#BufferEncoding" class="tsd-signature-type" data-tsd-kind="Type alias">BufferEncoding</a><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">number</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:336</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Returns the byte length of a string when encoded using <code>encoding</code>. This is not the same as <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length"><code>String.prototype.length</code></a>, which does not account for the encoding that is used to convert the string into bytes.</p> </div><div><p>For <code>&#39;base64&#39;</code>, <code>&#39;base64url&#39;</code>, and <code>&#39;hex&#39;</code>, this function assumes valid input. For strings that contain non-base64/hex-encoded data (e.g. whitespace), the return value might be greater than the length of a <code>Buffer</code> created from the string.</p> <pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">str</span><span class="hl-1"> = </span><span class="hl-5">&#39;</span><span class="hl-10">\u00bd</span><span class="hl-5"> + </span><span class="hl-10">\u00bc</span><span class="hl-5"> = </span><span class="hl-10">\u00be</span><span class="hl-5">&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-5">`</span><span class="hl-2">${</span><span class="hl-0">str</span><span class="hl-2">}</span><span class="hl-5">: </span><span class="hl-2">${</span><span class="hl-0">str</span><span class="hl-8">.</span><span class="hl-0">length</span><span class="hl-2">}</span><span class="hl-5"> characters, `</span><span class="hl-1"> +</span><br/><span class="hl-1"> </span><span class="hl-5">`</span><span class="hl-2">${</span><span class="hl-0">Buffer</span><span class="hl-8">.</span><span class="hl-4">byteLength</span><span class="hl-8">(</span><span class="hl-0">str</span><span class="hl-8">, </span><span class="hl-5">&#39;utf8&#39;</span><span class="hl-8">)</span><span class="hl-2">}</span><span class="hl-5"> bytes`</span><span class="hl-1">);</span><br/><span class="hl-7">// Prints: ½ + ¼ = ¾: 9 characters, 12 bytes</span> </code></pre> <p>When <code>string</code> is a <code>Buffer</code>/<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/DataView"><code>DataView</code></a>/[<code>TypedArray</code>](<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/-">https://developer.mozilla.org/en-US/docs/Web/JavaScript/-</a> Reference/Global_Objects/TypedArray)/<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/ArrayBuffer"><code>ArrayBuffer</code></a>/[<code>SharedArrayBuffer</code>](<a href="https://develop-">https://develop-</a> er.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/SharedArrayBuffer), the byte length as reported by <code>.byteLength</code>is returned.</p> </div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.1.90</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>string: <span class="tsd-signature-type">string</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">ArrayBuffer</span><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#SharedArrayBuffer-1" class="tsd-signature-type" data-tsd-kind="Variable">SharedArrayBuffer</a><span class="tsd-signature-symbol"> | </span><a href="../modules/_internal_.html#ArrayBufferView" class="tsd-signature-type" data-tsd-kind="Type alias">ArrayBufferView</a></h5><div class="tsd-comment tsd-typography"><div class="lead"> <p>A value to calculate the length of.</p> </div></div></li><li><h5><span class="tsd-flag ts-flagOptional">Optional</span> encoding: <a href="../modules/_internal_.html#BufferEncoding" class="tsd-signature-type" data-tsd-kind="Type alias">BufferEncoding</a></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">number</span></h4><div><p>The number of bytes contained within <code>string</code>.</p> </div></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a id="compare" class="tsd-anchor"></a><h3 class="tsd-anchor-link">compare<a href="#compare" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">compare<span class="tsd-signature-symbol">(</span>buf1<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Uint8Array</span>, buf2<span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">Uint8Array</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><span class="tsd-signature-type">0</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">1</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">-1</span></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/node/buffer.d.ts:393</li></ul></aside><div class="tsd-comment tsd-typography"><div class="lead"> <p>Compares <code>buf1</code> to <code>buf2</code>, typically for the purpose of sorting arrays of<code>Buffer</code> instances. This is equivalent to calling <code>buf1.compare(buf2)</code>.</p> </div><div><pre><code class="language-js"><span class="hl-6">import</span><span class="hl-1"> { </span><span class="hl-0">Buffer</span><span class="hl-1"> } </span><span class="hl-6">from</span><span class="hl-1"> </span><span class="hl-5">&#39;buffer&#39;</span><span class="hl-1">;</span><br/><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">buf1</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">from</span><span class="hl-1">(</span><span class="hl-5">&#39;1234&#39;</span><span class="hl-1">);</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">buf2</span><span class="hl-1"> = </span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-4">from</span><span class="hl-1">(</span><span class="hl-5">&#39;0123&#39;</span><span class="hl-1">);</span><br/><span class="hl-2">const</span><span class="hl-1"> </span><span class="hl-3">arr</span><span class="hl-1"> = [</span><span class="hl-0">buf1</span><span class="hl-1">, </span><span class="hl-0">buf2</span><span class="hl-1">];</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-4">log</span><span class="hl-1">(</span><span class="hl-0">arr</span><span class="hl-1">.</span><span class="hl-4">sort</span><span class="hl-1">(</span><span class="hl-0">Buffer</span><span class="hl-1">.</span><span class="hl-0">compare</span><span class="hl-1">));</span><br/><span class="hl-7">// Prints: [ &lt;Buffer 30 31 32 33&gt;, &lt;Buffer 31 32 33 34&gt; ]</span><br/><span class="hl-7">// (This result is equal to: [buf2, buf1].)</span> </code></pre> </div><dl class="tsd-comment-tags"><dt>since</dt><dd><p>v0.11.13</p> </dd></dl></div><h4 class="tsd-parameters-title">Parameters</h4><ul class="tsd-parameters"><li><h5>buf1: <span class="tsd-signature-type">Uint8Array</span></h5></li><li><h5>buf2: <span class="tsd-signature-type">Uint8Array</span></h5></li></ul><h4 class="tsd-returns-title">Returns <span class="tsd-signature-type">0</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">1</span><span class="tsd-signature-symbol"> | </span><span class="tsd-signature-type">-1</span></h4><div><p>Either <code>-1</code>, <code>0</code>, or <code>1</code>, depending on the result of the comparison. See <code>compare</code> for details.</p> </div></li></ul></section><section class="tsd-panel tsd-member tsd-kind-method tsd-parent-kind-interface tsd-is-external"><a id="concat" class="tsd-anchor"></a><h3 class="tsd-anchor-link">concat<a href="#concat" aria-label="Permalink" class="tsd-anchor-icon"><svg xmlns="http://www.w3.org/2000/svg" class="icon icon-tabler icon-tabler-link" viewBox="0 0 24 24" stroke-width="2" stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round"><path stroke="none" d="M0 0h24v24H0z" fill="none"></path><path d="M10 14a3.5 3.5 0 0 0 5 0l4 -4a3.5 3.5 0 0 0 -5 -5l-.5 .5"></path><path d="M14 10a3.5 3.5 0 0 0 -5 0l-4 4a3.5 3.5 0 0 0 5 5l.5 -.5"></path></svg></a></h3><ul class="tsd-signatures tsd-kind-method tsd-parent-kind-interface tsd-is-external"><li class="tsd-signature tsd-kind-icon">concat<span class="tsd-signature-symbol">(</span>list<span class="tsd-signature-symbol">: </span><span class="tsd-signature-symbol">readonly </span><span class="tsd-signature-type">Uint8Array</span><span class="tsd-signature-symbol">[]</span>, totalLength<span class="tsd-signature-symbol">?: </span><span class="tsd-signature-type">number</span><span class="tsd-signature-symbol">)</span><span class="tsd-signature-symbol">: </span><a href="../modules/_internal_.html" class="tsd-signature-type" data-tsd-kind="Namespace">&lt;internal&gt;</a><span class="tsd-signature-symbol">.</span><a href="../modules/_internal_.html#Buffer-1" class="tsd-signature-type" data-tsd-kind="Variable">Buffer</a></li></ul><ul class="tsd-descriptions"><li class="tsd-description"><aside class="tsd-sources"><ul><li>Defined in node_modules/@types/