<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>http://wiki.eijux.com/index.php?action=history&amp;feed=atom&amp;title=Node.js%EF%BC%9ABuffer</id>
	<title>Node.js：Buffer - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="http://wiki.eijux.com/index.php?action=history&amp;feed=atom&amp;title=Node.js%EF%BC%9ABuffer"/>
	<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;action=history"/>
	<updated>2026-05-05T10:20:17Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.38.2</generator>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=6445&amp;oldid=prev</id>
		<title>2023年3月31日 (五) 13:17 Eijux</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=6445&amp;oldid=prev"/>
		<updated>2023-03-31T13:17:25Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2023年3月31日 (五) 21:17的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;第1行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第1行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[category:Node.js教程]]&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 关于 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 关于 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，必须使用到二进制数据。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，必须使用到二进制数据。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=6444&amp;oldid=prev</id>
		<title>2023年3月31日 (五) 13:16 Eijux</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=6444&amp;oldid=prev"/>
		<updated>2023-03-31T13:16:05Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2023年3月31日 (五) 21:16的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l1&quot;&gt;第1行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第1行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;[[category:Node.js]]&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 关于 ==&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== 关于 ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，必须使用到二进制数据。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，必须使用到二进制数据。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4093&amp;oldid=prev</id>
		<title>Eijux：​/* Buffer使用 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4093&amp;oldid=prev"/>
		<updated>2021-05-30T13:08:06Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Buffer使用&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;a href=&quot;http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;amp;diff=4093&amp;amp;oldid=4092&quot;&gt;显示更改&lt;/a&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4092&amp;oldid=prev</id>
		<title>Eijux：​/* Buffer 与字符编码 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4092&amp;oldid=prev"/>
		<updated>2021-05-30T13:07:25Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Buffer 与字符编码&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月30日 (日) 21:07的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l17&quot;&gt;第17行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第17行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;通过使用显式的字符编码，就可以在 Buffer 实例与普通的 JavaScript 字符串之间进行相互转换：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;通过使用显式的字符编码，就可以在 Buffer 实例与普通的 JavaScript 字符串之间进行相互转换：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;bash&lt;/del&gt;&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;JavaScript&lt;/ins&gt;&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.from('runoob', 'ascii');&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.from('runoob', 'ascii');&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4088&amp;oldid=prev</id>
		<title>Eijux：​/* 附：方法参考手册 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4088&amp;oldid=prev"/>
		<updated>2021-05-30T13:05:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;附：方法参考手册&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月30日 (日) 21:05的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l345&quot;&gt;第345行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第345行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位无符号整数，小端对齐。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位无符号整数，小端对齐。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;示例：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;示例：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;bash&lt;/del&gt;&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;JavaScript&lt;/ins&gt;&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l357&quot;&gt;第357行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第357行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位无符号整数，大端对齐。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位无符号整数，大端对齐。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;示例：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;示例：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;bash&lt;/del&gt;&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;JavaScript&lt;/ins&gt;&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4087&amp;oldid=prev</id>
		<title>Eijux：​/* 附：方法参考手册 */</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4087&amp;oldid=prev"/>
		<updated>2021-05-30T13:04:04Z</updated>

		<summary type="html">&lt;p&gt;&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;附：方法参考手册&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2021年5月30日 (日) 21:04的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l317&quot;&gt;第317行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第317行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| new Buffer(size)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| new Buffer(size)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;分配一个新的 size 大小单位为8位字节的 buffer。 注意, size 必须小于 kMaxLength，否则，将会抛出异常 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;RangeError。废弃的: 使用 &lt;/del&gt;Buffer.alloc() 代替（或 Buffer.allocUnsafe()）。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;分配一个新的 size 大小单位为8位字节的 buffer。  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/ins&gt;注意, size 必须小于 kMaxLength，否则，将会抛出异常 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;RangeError。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* '''已废弃'''：使用 &lt;/ins&gt;Buffer.alloc() 代替（或 Buffer.allocUnsafe()）。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| new Buffer(buffer)&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| new Buffer(buffer)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;拷贝参数 buffer 的数据到 Buffer &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;实例。废弃的: 使用 &lt;/del&gt;Buffer.from(buffer) 代替。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;拷贝参数 buffer 的数据到 Buffer &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;实例。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* '''已废弃'''：使用 &lt;/ins&gt;Buffer.from(buffer) 代替。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| new Buffer(str[, encoding])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| new Buffer(str[, encoding])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;分配一个新的 buffer ，其中包含着传入的 str 字符串。 encoding 编码方式默认为 'utf8'。 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;废弃的: 使用 &lt;/del&gt;Buffer.from(string[, encoding]) 代替。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;分配一个新的 buffer ，其中包含着传入的 str 字符串。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/ins&gt;encoding 编码方式默认为 'utf8'。  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* '''已废弃'''：使用 &lt;/ins&gt;Buffer.from(string[, encoding]) 代替。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.length&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.length&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;返回这个 buffer 的 bytes &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;数。注意这未必是 &lt;/del&gt;buffer &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;里面内容的大小。length &lt;/del&gt;是 buffer 对象所分配的内存数，它不会随着这个 buffer 对象内容的改变而改变。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;返回这个 buffer 的 bytes &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;数。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* 注意这未必是 &lt;/ins&gt;buffer &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;里面内容的大小。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* length &lt;/ins&gt;是 buffer 对象所分配的内存数，它不会随着这个 buffer 对象内容的改变而改变。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.write(string[, offset[, length]][, encoding])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.write(string[, offset[, length]][, encoding])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;根据参数 offset 偏移量和指定的 encoding 编码方式，将参数 string 数据写入buffer。 offset 偏移量默认值是 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;0, encoding &lt;/del&gt;编码方式默认是 utf8。 length 长度是将要写入的字符串的 bytes &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;大小。 &lt;/del&gt;返回 number 类型，表示写入了多少 8 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;位字节流。如果 &lt;/del&gt;buffer 没有足够的空间来放整个 string，它将只会只写入部分字符串。 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;length 默认是 buffer.length - offset。 这个方法不会出现写入部分字符。&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;根据参数 offset 偏移量和指定的 encoding 编码方式，将参数 string 数据写入buffer。  &lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/ins&gt;offset 偏移量默认值是 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;0，encoding &lt;/ins&gt;编码方式默认是 utf8。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/ins&gt;length 长度是将要写入的字符串的 bytes &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;大小，默认是 buffer.length - offset。 &lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* &lt;/ins&gt;返回 number 类型，表示写入了多少 8 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;位字节流。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* 如果 &lt;/ins&gt;buffer 没有足够的空间来放整个 string，它将只会只写入部分字符串。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeUIntLE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeUIntLE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;位无符号整数，小端对齐，例如：&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;位无符号整数，小端对齐。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;示例：&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l339&quot;&gt;第339行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第351行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// 输出: &amp;lt;Buffer ab 90 78 56 34 12&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;// 输出: &amp;lt;Buffer ab 90 78 56 34 12&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;console.log(buf);&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/syntaxhighlight&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;console.log(buf);noAssert 值为 true 时，不再验证 value 和 offset 的有效性。 默认是 false。&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-added&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeUIntBE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeUIntBE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;位无符号整数，大端对齐。noAssert 值为 true 时，不再验证 value 和 offset 的有效性。 默认是 false。&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;| &lt;/ins&gt;将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;位无符号整数，大端对齐。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;示例：&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;const buf = Buffer.allocUnsafe(6);&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l354&quot;&gt;第354行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第367行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeIntLE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeIntLE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 将 value 写入到 buffer &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;里， 它由 &lt;/del&gt;offset 和 byteLength 决定，最高支持 48 位有符号整数，小端对齐。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 将 value 写入到 buffer &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;里，它由 &lt;/ins&gt;offset 和 byteLength 决定，最高支持 48 位有符号整数，小端对齐。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeIntBE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.writeIntBE(value, offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;将value &lt;/del&gt;写入到 buffer &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;里， 它由 &lt;/del&gt;offset 和 byteLength &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;决定，最高支持48位有符号整数，大端对齐。&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;将 value &lt;/ins&gt;写入到 buffer &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;里，它由 &lt;/ins&gt;offset 和 byteLength &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;决定，最高支持 48 位有符号整数，大端对齐。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.readUIntLE(offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.readUIntLE(offset, byteLength[, noAssert])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l494&quot;&gt;第494行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第507行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|-&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.fill(value[, offset][, end])&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| buf.fill(value[, offset][, end])&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 使用指定的 value 来填充这个 &lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;buffer。如果没有指定 &lt;/del&gt;offset (默认是 0) 并且 end (默认是 buffer.length) ，将会填充整个buffer。&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;| 使用指定的 value 来填充这个 &lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;buffer。&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;* 如果没有指定 &lt;/ins&gt;offset (默认是 0) 并且 end (默认是 buffer.length) ，将会填充整个buffer。&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|}&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;|}&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;br/&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
	<entry>
		<id>http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4086&amp;oldid=prev</id>
		<title>Eijux：​建立内容为“category:Node.js  == 关于 == JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，…”的新页面</title>
		<link rel="alternate" type="text/html" href="http://wiki.eijux.com/index.php?title=Node.js%EF%BC%9ABuffer&amp;diff=4086&amp;oldid=prev"/>
		<updated>2021-05-30T12:45:24Z</updated>

		<summary type="html">&lt;p&gt;建立内容为“&lt;a href=&quot;/%E5%88%86%E7%B1%BB:Node.js&quot; title=&quot;分类:Node.js&quot;&gt;category:Node.js&lt;/a&gt;  == 关于 == JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，…”的新页面&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[category:Node.js]]&lt;br /&gt;
&lt;br /&gt;
== 关于 ==&lt;br /&gt;
JavaScript 语言自身只有字符串数据类型，没有二进制数据类型。但在处理像 TCP流 或 文件流 时，必须使用到二进制数据。&lt;br /&gt;
&lt;br /&gt;
因此在 Node.js中，定义了一个 '''Buffer 类'''，该类用来创建一个专门存放'''二进制'''数据的缓存区。&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
在 Node.js 中，Buffer 类是随 Node 内核一起发布的核心库。Buffer 库为 Node.js 带来了一种存储原始数据的方法，可以让 Node.js 处理二进制数据，每当需要在 Node.js 中处理I/O操作中移动的数据时，就有可能使用 Buffer 库。原始数据存储在 Buffer 类的实例中。&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
* 一个 Buffer 类似于一个整数数组，但它对应于 V8 堆内存之外的一块原始内存。&lt;br /&gt;
* 在 v6.0 之前创建 Buffer 对象直接使用 new Buffer() 构造函数来创建对象实例，但是 Buffer 对内存的权限操作相比很大，可以直接捕获一些敏感信息，所以在 v6.0 以后，官方文档里面建议使用 '''Buffer.from()''' 接口去创建 Buffer 对象。&lt;br /&gt;
&lt;br /&gt;
=== Buffer 与字符编码 ===&lt;br /&gt;
Buffer 实例一般用于表示编码字符的序列，比如 UTF-8 、 UCS2 、 Base64 、或十六进制编码的数据。 &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
通过使用显式的字符编码，就可以在 Buffer 实例与普通的 JavaScript 字符串之间进行相互转换：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
const buf = Buffer.from('runoob', 'ascii');&lt;br /&gt;
&lt;br /&gt;
// 输出 72756e6f6f62&lt;br /&gt;
console.log(buf.toString('hex'));&lt;br /&gt;
&lt;br /&gt;
// 输出 cnVub29i&lt;br /&gt;
console.log(buf.toString('base64'));&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Node.js 目前支持的字符编码包括：&lt;br /&gt;
* ascii：仅支持 7 位 ASCII 数据。如果设置去掉高位的话，这种编码是非常快的。&lt;br /&gt;
* utf8：多字节编码的 Unicode 字符。许多网页和其他文档格式都使用 UTF-8 。&lt;br /&gt;
* utf16le：2 或 4 个字节，小字节序编码的 Unicode 字符。支持代理对（U+10000 至 U+10FFFF）。&lt;br /&gt;
* ucs2：（utf16le 的别名）。&lt;br /&gt;
* base64：Base64 编码。&lt;br /&gt;
* latin1：一种把 Buffer 编码成一字节编码的字符串的方式。&lt;br /&gt;
* binary：（latin1 的别名）。&lt;br /&gt;
* hex：将每个字节编码为两个十六进制字符。&lt;br /&gt;
&lt;br /&gt;
== Buffer使用 ==&lt;br /&gt;
&lt;br /&gt;
=== 创建 Buffer 类 ===&lt;br /&gt;
Buffer 提供了以下 API 来创建 Buffer 类：&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.alloc(size[, fill[, encoding]])&amp;lt;/code&amp;gt;'''： 返回一个指定大小的 Buffer 实例，如果没有设置 fill，则默认填满 0；&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.allocUnsafe(size)&amp;lt;/code&amp;gt;'''： 返回一个指定大小的 Buffer 实例，但是它'''不会被初始化'''，所以它可能包含敏感的数据；&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.allocUnsafeSlow(size)&amp;lt;/code&amp;gt;'''： &lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.from(array)&amp;lt;/code&amp;gt;'''： 返回一个被 array 的值初始化的新的 Buffer 实例（传入的 array 的元素只能是数字，不然就会自动被 0 覆盖）；&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.from(arrayBuffer[, byteOffset[, length]])&amp;lt;/code&amp;gt;'''： 返回一个新建的与给定的 ArrayBuffer 共享同一内存的 Buffer；【？】&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.from(string[, encoding])&amp;lt;/code&amp;gt;'''： 返回一个被 string 的值初始化的新的 Buffer 实例；&lt;br /&gt;
* '''&amp;lt;code&amp;gt;Buffer.from(buffer)&amp;lt;/code&amp;gt;'''： 复制传入的 Buffer 实例的数据，并返回一个新的 Buffer 实例；&lt;br /&gt;
&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
// 创建一个长度为 10、且用 0 填充的 Buffer。&lt;br /&gt;
const buf1 = Buffer.alloc(10);&lt;br /&gt;
&lt;br /&gt;
// 创建一个长度为 10、且用 0x1 填充的 Buffer。 &lt;br /&gt;
const buf2 = Buffer.alloc(10, 1);&lt;br /&gt;
&lt;br /&gt;
// 创建一个长度为 10、且未初始化的 Buffer。&lt;br /&gt;
// 这个方法比调用 Buffer.alloc() 更快，&lt;br /&gt;
// 但返回的 Buffer 实例可能包含旧数据，&lt;br /&gt;
// 因此需要使用 “fill()” 或 “write()” 重写。&lt;br /&gt;
const buf3 = Buffer.allocUnsafe(10);&lt;br /&gt;
&lt;br /&gt;
// 创建一个包含 [0x1, 0x2, 0x3] 的 Buffer。&lt;br /&gt;
const buf4 = Buffer.from([1, 2, 3]);&lt;br /&gt;
&lt;br /&gt;
// 创建一个包含 UTF-8 字节 [0x74, 0xc3, 0xa9, 0x73, 0x74] 的 Buffer。&lt;br /&gt;
const buf5 = Buffer.from('tést');&lt;br /&gt;
&lt;br /&gt;
// 创建一个包含 Latin-1 字节 [0x74, 0xe9, 0x73, 0x74] 的 Buffer。&lt;br /&gt;
const buf6 = Buffer.from('tést', 'latin1');&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 写入缓冲区 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.write(string[, offset[, length]][, encoding])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
参数：&lt;br /&gt;
* string - 写入缓冲区的字符串。&lt;br /&gt;
* offset - 缓冲区开始写入的索引值，默认为 0 。&lt;br /&gt;
* length - 写入的字节数，默认为 buffer.length。&lt;br /&gt;
* encoding - 使用的编码。默认为 'utf8' 。&lt;br /&gt;
: 根据 encoding 的字符编码写入 string 到 buf 中的 offset 位置。 length 参数是写入的字节数。 如果 buf 没有足够的空间保存整个字符串，则只会写入 string 的一部分。 只部分解码的字符不会被写入。&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 返回实际写入的大小。如果 buffer 空间不足， 则只会写入部分字符串。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf = Buffer.alloc(256);&lt;br /&gt;
len = buf.write(&amp;quot;www.runoob.com&amp;quot;);&lt;br /&gt;
&lt;br /&gt;
console.log(&amp;quot;写入字节数 : &amp;quot;+  len);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
$node main.js&lt;br /&gt;
写入字节数 : 14&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 读取缓冲区 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.toString([encoding[, start[, end]]])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
参数：&lt;br /&gt;
* encoding - 使用的编码。默认为 'utf8' 。&lt;br /&gt;
* start - 指定开始读取的索引位置，默认为 0。&lt;br /&gt;
* end - 结束位置，默认为缓冲区的末尾。&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 解码缓冲区数据并使用指定的编码返回字符串。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf = Buffer.alloc(26);&lt;br /&gt;
for (var i = 0 ; i &amp;lt; 26 ; i++) {&lt;br /&gt;
  buf[i] = i + 97;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
console.log( buf.toString('ascii'));       // 输出: abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
console.log( buf.toString('ascii',0,5));   //使用 'ascii' 编码, 并输出: abcde&lt;br /&gt;
console.log( buf.toString('utf8',0,5));    // 使用 'utf8' 编码, 并输出: abcde&lt;br /&gt;
console.log( buf.toString(undefined,0,5)); // 使用默认的 'utf8' 编码, 并输出: abcde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
$ node main.js&lt;br /&gt;
abcdefghijklmnopqrstuvwxyz&lt;br /&gt;
abcde&lt;br /&gt;
abcde&lt;br /&gt;
abcde&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 将 Buffer 转换为 JSON 对象 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.toJSON()&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
: 当字符串化一个 Buffer 实例时，“JSON.stringify()” 会隐式地调用该 toJSON()。【？】&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 返回 JSON 对象。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
const buf = Buffer.from([0x1, 0x2, 0x3, 0x4, 0x5]);&lt;br /&gt;
const json = JSON.stringify(buf);&lt;br /&gt;
&lt;br /&gt;
// 输出: {&amp;quot;type&amp;quot;:&amp;quot;Buffer&amp;quot;,&amp;quot;data&amp;quot;:[1,2,3,4,5]}&lt;br /&gt;
console.log(json);&lt;br /&gt;
&lt;br /&gt;
const copy = JSON.parse(json, (key, value) =&amp;gt; {&lt;br /&gt;
  return value &amp;amp;&amp;amp; value.type === 'Buffer' ?&lt;br /&gt;
    Buffer.from(value.data) :&lt;br /&gt;
    value;&lt;br /&gt;
});&lt;br /&gt;
&lt;br /&gt;
// 输出: &amp;lt;Buffer 01 02 03 04 05&amp;gt;&lt;br /&gt;
console.log(copy);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
{&amp;quot;type&amp;quot;:&amp;quot;Buffer&amp;quot;,&amp;quot;data&amp;quot;:[1,2,3,4,5]}&lt;br /&gt;
&amp;lt;Buffer 01 02 03 04 05&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 合并缓冲区 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
Buffer.concat(list[, totalLength])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
参数：&lt;br /&gt;
* list - 用于合并的 Buffer 对象'''数组列表'''。&lt;br /&gt;
* totalLength - 指定合并后Buffer对象的总长度。&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 返回一个多个成员合并的新 Buffer 对象。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
var buffer1 = Buffer.from(('菜鸟教程'));&lt;br /&gt;
var buffer2 = Buffer.from(('www.runoob.com'));&lt;br /&gt;
var buffer3 = Buffer.concat([buffer1,buffer2]);&lt;br /&gt;
console.log(&amp;quot;buffer3 内容: &amp;quot; + buffer3.toString());&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buffer3 内容: 菜鸟教程www.runoob.com&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 比较缓冲区 ===&lt;br /&gt;
* 该方法在 Node.js v0.12.2 版本引入；&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.compare(otherBuffer);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
参数：&lt;br /&gt;
* otherBuffer - 与 buf 对象比较的另外一个 Buffer 对象。&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 返回一个数字，表示 buf 在 otherBuffer 之前，之后或相同。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
var buffer1 = Buffer.from('ABC');&lt;br /&gt;
var buffer2 = Buffer.from('ABCD');&lt;br /&gt;
var result = buffer1.compare(buffer2);&lt;br /&gt;
&lt;br /&gt;
if(result &amp;lt; 0) {&lt;br /&gt;
   console.log(buffer1 + &amp;quot; 在 &amp;quot; + buffer2 + &amp;quot;之前&amp;quot;);&lt;br /&gt;
}else if(result == 0){&lt;br /&gt;
   console.log(buffer1 + &amp;quot; 与 &amp;quot; + buffer2 + &amp;quot;相同&amp;quot;);&lt;br /&gt;
}else {&lt;br /&gt;
   console.log(buffer1 + &amp;quot; 在 &amp;quot; + buffer2 + &amp;quot;之后&amp;quot;);&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
ABC 在 ABCD之前&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 拷贝缓冲区 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
参数：&lt;br /&gt;
* targetBuffer - 要拷贝的 Buffer 对象。&lt;br /&gt;
* targetStart - 拷贝在目标缓冲区的插入位置：数字, 可选, 默认: 0。&lt;br /&gt;
* sourceStart - 源缓冲区中拷贝的开始位置：数字, 可选, 默认: 0。&lt;br /&gt;
* sourceEnd - 源缓冲区中拷贝的结束位置：数字, 可选, 默认: buffer.length。&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 没有返回值。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
var buf1 = Buffer.from('abcdefghijkl');&lt;br /&gt;
var buf2 = Buffer.from('RUNOOB');&lt;br /&gt;
&lt;br /&gt;
//将 buf2 插入到 buf1 指定位置上&lt;br /&gt;
buf2.copy(buf1, 2);&lt;br /&gt;
&lt;br /&gt;
console.log(buf1.toString());&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
abRUNOOBijkl&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 裁剪缓冲区 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.slice([start[, end]])&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
参数：&lt;br /&gt;
* start - 裁剪开始位置：数字, 可选, 默认: 0&lt;br /&gt;
* end - 裁剪结束位置：数字, 可选, 默认: buffer.length&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: '''返回一个新的缓冲区，它和旧缓冲区指向同一块内存'''，但是从索引 start 到 end 的位置剪切。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
var buffer1 = Buffer.from('runoob');&lt;br /&gt;
// 剪切缓冲区&lt;br /&gt;
var buffer2 = buffer1.slice(0,2);&lt;br /&gt;
console.log(&amp;quot;buffer2 content: &amp;quot; + buffer2.toString());&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buffer2 content: ru&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
=== 缓冲区长度 ===&lt;br /&gt;
语法：&lt;br /&gt;
'''&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buf.length;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;'''&lt;br /&gt;
&lt;br /&gt;
返回值：&lt;br /&gt;
: 返回 Buffer 对象所占据的内存长度。&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
示例：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
var buffer = Buffer.from('www.runoob.com');&lt;br /&gt;
//  缓冲区长度&lt;br /&gt;
console.log(&amp;quot;buffer length: &amp;quot; + buffer.length);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
执行以上代码，输出结果为：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
buffer length: 14&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 附：方法参考手册 ==&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! 命令 !! 描述 &lt;br /&gt;
|-&lt;br /&gt;
| new Buffer(size)&lt;br /&gt;
分配一个新的 size 大小单位为8位字节的 buffer。 注意, size 必须小于 kMaxLength，否则，将会抛出异常 RangeError。废弃的: 使用 Buffer.alloc() 代替（或 Buffer.allocUnsafe()）。&lt;br /&gt;
|-&lt;br /&gt;
| new Buffer(buffer)&lt;br /&gt;
拷贝参数 buffer 的数据到 Buffer 实例。废弃的: 使用 Buffer.from(buffer) 代替。&lt;br /&gt;
|-&lt;br /&gt;
| new Buffer(str[, encoding])&lt;br /&gt;
分配一个新的 buffer ，其中包含着传入的 str 字符串。 encoding 编码方式默认为 'utf8'。 废弃的: 使用 Buffer.from(string[, encoding]) 代替。&lt;br /&gt;
|-&lt;br /&gt;
| buf.length&lt;br /&gt;
返回这个 buffer 的 bytes 数。注意这未必是 buffer 里面内容的大小。length 是 buffer 对象所分配的内存数，它不会随着这个 buffer 对象内容的改变而改变。&lt;br /&gt;
|-&lt;br /&gt;
| buf.write(string[, offset[, length]][, encoding])&lt;br /&gt;
根据参数 offset 偏移量和指定的 encoding 编码方式，将参数 string 数据写入buffer。 offset 偏移量默认值是 0, encoding 编码方式默认是 utf8。 length 长度是将要写入的字符串的 bytes 大小。 返回 number 类型，表示写入了多少 8 位字节流。如果 buffer 没有足够的空间来放整个 string，它将只会只写入部分字符串。 length 默认是 buffer.length - offset。 这个方法不会出现写入部分字符。&lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUIntLE(value, offset, byteLength[, noAssert])&lt;br /&gt;
将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位无符号整数，小端对齐，例如：&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
const buf = Buffer.allocUnsafe(6);&lt;br /&gt;
&lt;br /&gt;
buf.writeUIntLE(0x1234567890ab, 0, 6);&lt;br /&gt;
&lt;br /&gt;
// 输出: &amp;lt;Buffer ab 90 78 56 34 12&amp;gt;&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
console.log(buf);noAssert 值为 true 时，不再验证 value 和 offset 的有效性。 默认是 false。&lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUIntBE(value, offset, byteLength[, noAssert])&lt;br /&gt;
将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位无符号整数，大端对齐。noAssert 值为 true 时，不再验证 value 和 offset 的有效性。 默认是 false。&lt;br /&gt;
&amp;lt;syntaxhighlight lang=&amp;quot;bash&amp;quot; highlight=&amp;quot;&amp;quot;&amp;gt;&lt;br /&gt;
const buf = Buffer.allocUnsafe(6);&lt;br /&gt;
&lt;br /&gt;
buf.writeUIntBE(0x1234567890ab, 0, 6);&lt;br /&gt;
&lt;br /&gt;
// 输出: &amp;lt;Buffer 12 34 56 78 90 ab&amp;gt;&lt;br /&gt;
console.log(buf);&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
|-&lt;br /&gt;
| buf.writeIntLE(value, offset, byteLength[, noAssert])&lt;br /&gt;
| 将 value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持 48 位有符号整数，小端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.writeIntBE(value, offset, byteLength[, noAssert])&lt;br /&gt;
| 将value 写入到 buffer 里， 它由 offset 和 byteLength 决定，最高支持48位有符号整数，大端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readUIntLE(offset, byteLength[, noAssert])&lt;br /&gt;
| 支持读取 48 位以下的无符号数字，小端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readUIntBE(offset, byteLength[, noAssert])&lt;br /&gt;
| 支持读取 48 位以下的无符号数字，大端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readIntLE(offset, byteLength[, noAssert])&lt;br /&gt;
| 支持读取 48 位以下的有符号数字，小端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readIntBE(offset, byteLength[, noAssert])&lt;br /&gt;
| 支持读取 48 位以下的有符号数字，大端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.toString([encoding[, start[, end]]])&lt;br /&gt;
| 根据 encoding 参数（默认是 'utf8'）返回一个解码过的 string 类型。&lt;br /&gt;
还会根据传入的参数 start (默认是 0) 和 end (默认是 buffer.length)作为取值范围。&lt;br /&gt;
|-&lt;br /&gt;
| buf.toJSON()&lt;br /&gt;
| 将 Buffer 实例转换为 JSON 对象。&lt;br /&gt;
|-&lt;br /&gt;
| buf[index]&lt;br /&gt;
| 获取或设置指定的字节。&lt;br /&gt;
返回值代表一个字节，所以返回值的合法范围是十六进制0x00到0xFF 或者十进制0至 255。&lt;br /&gt;
|-&lt;br /&gt;
| buf.equals(otherBuffer)&lt;br /&gt;
| 比较两个缓冲区是否相等，如果是返回 true，否则返回 false。&lt;br /&gt;
|-&lt;br /&gt;
| buf.compare(otherBuffer)&lt;br /&gt;
| 比较两个 Buffer 对象，返回一个数字，表示 buf 在 otherBuffer 之前，之后或相同。&lt;br /&gt;
|-&lt;br /&gt;
| buf.copy(targetBuffer[, targetStart[, sourceStart[, sourceEnd]]])&lt;br /&gt;
| buffer 拷贝，源和目标可以相同。&lt;br /&gt;
* targetStart（目标开始偏移）和 sourceStart（源开始偏移默认）都是 0。 &lt;br /&gt;
* sourceEnd（源结束位置偏移）默认是源的长度 buffer.length 。&lt;br /&gt;
|-&lt;br /&gt;
| buf.slice([start[, end]])&lt;br /&gt;
| 剪切 Buffer 对象，根据 start(默认是 0 ) 和 end (默认是 buffer.length ) 偏移和裁剪了索引。&lt;br /&gt;
* 负的索引是从 buffer 尾部开始计算的。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readUInt8(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，读取一个无符号 8 位整数。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readUInt16LE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用特殊的 endian 字节序格式读取一个无符号 16 位整数。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readUInt16BE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用特殊的 endian 字节序格式读取一个无符号 16 位整数，大端对齐。&lt;br /&gt;
|-&lt;br /&gt;
| buf.readUInt32LE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian 字节序格式读取一个无符号 32 位整数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readUInt32BE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian 字节序格式读取一个无符号 32 位整数，大端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readInt8(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，读取一个有符号 8 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readInt16LE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用特殊的 endian 格式读取一个 有符号 16 位整数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readInt16BE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用特殊的 endian 格式读取一个 有符号 16 位整数，大端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readInt32LE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian 字节序格式读取一个有符号 32 位整数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readInt32BE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian 字节序格式读取一个有符号 32 位整数，大端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readFloatLE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian 字节序格式读取一个 32 位双浮点数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readFloatBE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian 字节序格式读取一个 32 位双浮点数，大端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readDoubleLE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian字节序格式读取一个 64 位双精度数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.readDoubleBE(offset[, noAssert])&lt;br /&gt;
| 根据指定的偏移量，使用指定的 endian字节序格式读取一个 64 位双精度数，大端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUInt8(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量将 value 写入 buffer。注意：value 必须是一个合法的无符号 8 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUInt16LE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的无符号 16 位整数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUInt16BE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的无符号 16 位整数，大端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUInt32LE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式(LITTLE-ENDIAN:小字节序)将 value 写入buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的无符号 32 位整数，小端对齐。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeUInt32BE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式(Big-Endian:大字节序)将 value 写入buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的有符号 32 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeInt8(value, offset[, noAssert])&lt;br /&gt;
| &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeInt16LE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的 signed 16 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeInt16BE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的 signed 16 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeInt32LE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的 signed 32 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeInt32BE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个合法的 signed 32 位整数。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeFloatLE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer 。&lt;br /&gt;
* 注意：当 value 不是一个 32 位浮点数类型的值时，结果将是不确定的。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeFloatBE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer 。&lt;br /&gt;
* 注意：当 value 不是一个 32 位浮点数类型的值时，结果将是不确定的。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeDoubleLE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个有效的 64 位double 类型的值。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.writeDoubleBE(value, offset[, noAssert])&lt;br /&gt;
| 根据传入的 offset 偏移量和指定的 endian 格式将 value 写入 buffer。&lt;br /&gt;
* 注意：value 必须是一个有效的 64 位double 类型的值。 &lt;br /&gt;
|-&lt;br /&gt;
| buf.fill(value[, offset][, end])&lt;br /&gt;
| 使用指定的 value 来填充这个 buffer。如果没有指定 offset (默认是 0) 并且 end (默认是 buffer.length) ，将会填充整个buffer。&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
关于“noAssert”参数：&lt;br /&gt;
* 默认是 false；&lt;br /&gt;
* 若为 true 将不会验证 value 和 offset 偏移量参数：这意味着 value 可能过大，或者 offset 可能会超出 buffer 的末尾从而造成 value 被丢弃；&lt;br /&gt;
* 除非你对这个参数非常有把握，否则尽量不要使用。&lt;/div&gt;</summary>
		<author><name>Eijux</name></author>
	</entry>
</feed>