模极社社区 - 制造业全产业链交流平台

    • 登录
    • 版块
    • 最新
    • 话题
    • 热门
    • 用户
    • 群组

    Buffer From——模具行业从业者必备知识手册

    社区公告
    1
    1
    0
    正在加载更多帖子
    • 从旧到新
    • 从新到旧
    • 最多赞同
    回复
    • 在新帖中回复
    登录后回复
    此主题已被删除。只有拥有主题管理权限的用户可以查看。
    • S
      system 2 最后由 编辑

      <h2>Buffer From</h2>

      <p>A <a href="https://ponyfill.com">ponyfill</a> for <code>Buffer.from</code>, uses native implementation if available.</p>

      <h3>Installation</h3>

      <pre><code>
      npm install --save buffer-from
      </code></pre>

      <h3>Usage</h3>

      <pre><code>
      const bufferFrom = require('buffer-from')

      console.log(bufferFrom([1, 2, 3, 4]))
      //=> <Buffer 01 02 03 04>

      const arr = new Uint8Array([1, 2, 3, 4])
      console.log(bufferFrom(arr.buffer, 1, 2))
      //=> <Buffer 02 03>

      console.log(bufferFrom('test', 'utf8'))
      //=> <Buffer 74 65 73 74>

      const buf = bufferFrom('test')
      console.log(bufferFrom(buf))
      //=> <Buffer 74 65 73 74>
      </code></pre>

      <h3>API</h3>

      <h4>bufferFrom(array)</h4>

      <ul>
      <li><code>array</code> &lt;Array&gt;</li>
      </ul>

      <p>Allocates a new <code>Buffer</code> using an <code>array</code> of octets.</p>

      <h4>bufferFrom(arrayBuffer[, byteOffset[, length]])</h4>

      <ul>
      <li><code>arrayBuffer</code> &lt;ArrayBuffer&gt; The <code>.buffer</code> property of a TypedArray or ArrayBuffer</li>
      <li><code>byteOffset</code> &lt;Integer&gt; Where to start copying from <code>arrayBuffer</code>. <strong>Default:</strong> <code>0</code></li>
      <li><code>length</code> &lt;Integer&gt; How many bytes to copy from <code>arrayBuffer</code>. <strong>Default:</strong> <code>arrayBuffer.length - byteOffset</code></li>
      </ul>

      <p>When passed a reference to the <code>.buffer</code> property of a TypedArray instance, the</p>
      <p>newly created <code>Buffer</code> will share the same allocated memory as the TypedArray.</p>

      <p>The optional <code>byteOffset</code> and <code>length</code> arguments specify a memory range within</p>
      <p>the <code>arrayBuffer</code> that will be shared by the <code>Buffer</code>.</p>

      <h4>bufferFrom(buffer)</h4>

      <ul>
      <li><code>buffer</code> &lt;Buffer&gt; An existing <code>Buffer</code> to copy data from</li>
      </ul>

      <p>Copies the passed <code>buffer</code> data onto a new <code>Buffer</code> instance.</p>

      <h4>bufferFrom(string[, encoding])</h4>

      <ul>
      <li><code>string</code> &lt;String&gt; A string to encode.</li>
      <li><code>encoding</code> &lt;String&gt; The encoding of <code>string</code>. <strong>Default:</strong> <code>'utf8'</code></li>
      </ul>

      <p>Creates a new <code>Buffer</code> containing the given JavaScript string <code>string</code>. If</p>
      <p>provided, the <code>encoding</code> parameter identifies the character encoding of</p>
      <p><code>string</code>.</p>

      <h3>See also</h3>

      <ul>
      <li><a href="https://github.com/LinusU/buffer-alloc">buffer-alloc</a> A ponyfill for <code>Buffer.alloc</code></li>
      <li><a href="https://github.com/LinusU/buffer-alloc-unsafe">buffer-alloc-unsafe</a> A ponyfill for <code>Buffer.allocUnsafe</code></li>
      </ul>

      <hr>

      <p>本文由模极社发布</p>

      <hr>
      <p>!<a href="upload://cTUm8tHLABMewfCKi5BBEMzPd5E.svg">Buffer From</a></p>

      <hr>
      <h4>🔗 你可能还感兴趣</h4>
      <ul>
      <li><a href="/t/2878/2878">变频节能改造工艺详解与模具技术指南</a></li>
      <li><a href="/t/4437/4437">@babel/plugin-transform-class-static-block</a></li>
      <li><a href="/t/2988/2988">压射比压参数设置与工艺优化指南</a></li>
      </ul>

      <hr>
      <p><strong>相关推荐:</strong></p>
      <ul>
      <li><a href="https://www.mj7.cn/t/4836-4836">北京模具产业 — 科技研发驱动型模具基地</a></li>
      <li><a href="https://www.mj7.cn/t/4835-4835">上海模具产业 — 高端精密模具研发中心</a></li>
      <li><a href="https://www.mj7.cn/t/4834-4834">产业集群与模具产业发展的关系</a></li>
      </ul>

      <hr>
      <p>有没有同行遇到过同样的问题?分享一下经验。</p>

      1 条回复 最后回复 回复 引用 0
      • First post
        Last post
      Powered by NodeBB | Contributors