>> node
>>fs.readFile('finnish.txt', function(err,data){
console.log(data);
});
// Output string is not what we want >>fs.readFile('finnish.txt', function(err, data){
console.log(data.toString());
});
// Ouptu is ok /* Encoding */
>>fs.readFile('finnish.txt', 'utf8', function(err,data){
console.log(data);
});
// Ouptu is ok >>str = '\u0048\u0065\u006c\u006f \u0057\u006f\u0072\u006c\u0064\u0021';
'Hello World' str.length
12 Buffer.byteLength(str, 'utf8')
12 But the Buffer.byteLength and str.length are not equal!! ------ >>str = '\u00bd + \u00bc = \u00be';
'1/2 + 1/4 = 3/4'; str.length
9 Buffer.byteLength(str, 'utf8')
12 ----- >>buf = new Buffer(5)
>>buf.write('hello wolrd');
>>buf.toString()
'hello' >>buf.write('hello', 2);
hehel >>buf.write('xxxx', 2, 1);
>>buf.toString()
hexel >>buf.write('xxxx', 2, 2);
>>buf.toString()
hexxel >>buf.write('yyyy', 2, 1, 'utf8')
>>buf.toString()
heyel ----- buf1 = new Buffer('1234')
buf2 = new Buffer('0123')
buf3 = new Buffer('1234') buf1.compare(buf2)
1 //not equal
buf1.compare(buf3)
0 //equal buf1.equals(buf2)
false >>var arr = [buf1, buf2]
>>arr.sort(Buffer.compare)
[ <Buffer 30 31 32 33>, <Buffer 31 32 33 34> ] >>buf.toJSON()
{type: 'Buffer', data: [104, 101, 121, 101, 108]} >> buf = new Buffer('Hello World!');
>> buf2 0 buf.slice(0,3) buf2.toString();
'Hel'

In this lesson, we cover the Node.js Buffer object in detail. Not only will you learn that the buffer object is a reference to a memory space outside of the V8 engine, but you will learn practical methods to access it, modify it, and convert it to standard Javascript objects that can be used by your code. Examples and discussion are provided for using the toString() method, determining the byte length of the buffer, writing to a buffer, how to avoid truncating data, comparing buffers for equality using both compare() and equals(), and copying buffers using slice().

最新文章

  1. .NET缓存框架CacheManager在混合式开发框架中的应用(1)-CacheManager的介绍和使用
  2. Windows下80端口被pid为4的System进程占用解决方法
  3. set的应用
  4. json2.js源码解读记录
  5. linux卸载openJDK并安装sun jdk
  6. shell如何在指定文件的指定位置后面添加内容
  7. BZOJ3806: Neerc2011 Dictionary Size
  8. 安卓tabhost和子Activity通信方法
  9. Android Fragment中使用Intent组件拍照
  10. Python基础之 urllib模块urlopen()与urlretrieve()的使用方法详解。
  11. leetcode[87] Partition List
  12. 题目1032:ZOJ
  13. MAC OS X下的Linux环境
  14. Embedded servlet containers
  15. hibernate 查询字段是重复名字的处理方法
  16. zabbix图形乱码问题解决办法
  17. H264三种码率控制方法(CBR, VBR, CVBR)
  18. flask_admin 笔记七 扩展功能
  19. centos安装Python插件后找不到对应的插件ModuleNotFoundError: No module named*
  20. 自定义MVC视图引擎ViewEngine 创建Model的专属视图

热门文章

  1. leetcode第八题 String to Integer (atoi) (java)
  2. 【原创】Matlab中plot函数全功能解析
  3. Entity FrameWork知识点汇总
  4. 如何监控 Tomcat?Zabbix 与 Cloud Insight 对比
  5. struts2文件下载出现Can not find a java.io.InputStream with the name的错误
  6. [wikioi]乘积最大
  7. Qt源码分析之QPointer
  8. C#判断操作系统类型汇总
  9. Properties vs. Attributes
  10. XP中IIS&ldquo;HTTP 500 - 内部服务器错误&rdquo;解决方法