>> 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().

[Node.js] Node.js Buffers的更多相关文章

  1. 在Sublime Text 3 中安装SublimeLinter,Node.js进行JS&CSS代码校验

    转载自:http://www.wiibil.com/website/sublimelinter-jshint-csslint.html 在Sublime Text中安装SublimeLinter,No ...

  2. JS, Node.js, npm简介

    序 听过JS,听过Node,也听过Node.js,还听过npm,然而并不是很清楚的知道都代表什么,这两天调接口,然后前端同学很忙,就自己把前端代码拿过来跑了,也趁机了解一下这几个概念,下边做个小的总结 ...

  3. node-sass 安装卡在 node scripts/install.js 解决办法

    转自:https://segmentfault.com/a/1190000005921721 ======== 7月12日更新 ======== 总的来说就是两种方法解决: SASS_BINARY_S ...

  4. [Node.js] Node + Redis 实现分布式Session方案

    原文地址: http://www.moye.me/?p=565 Session是什么? Session 是面向连接的状态信息,是对 Http 无状态协议的补充. Session 怎么工作? Sessi ...

  5. soket.io.js + angular.js + express.js(node.js)

    soket.io.js + angular.js + express.js(node.js) 今天搭建个soket.io.js + angular.js + express.js的环境, 采坑无数,特 ...

  6. 一统江湖的大前端(2)—— Mock.js + Node.js 如何与后端潇洒分手

    <一统江湖的大前端>系列是自己的前端学习笔记,旨在介绍javascript在非网页开发领域的应用案例和发现各类好玩的js库,不定期更新.如果你对前端的理解还是写写页面绑绑事件,那你真的是有 ...

  7. node.js(node.js+mongoose小案例)_实现简单的注册登录退出

    一.前言 通过node.js基本知识对node.js基本知识的一个简单应用 1.注册 2.登录 3.退出 二.基本内容 1.项目结构搭建如图所示 2.这个小案列中用到了art-template子模板以 ...

  8. node scripts/install.js 停顿解决办法

    参考:node-sass 安装卡在 node scripts/install.js 解决办法 在安装hexo的时候,运行: npm install hexo-cli -g 卡死在了 node scri ...

  9. node启动appium.js

    node启动appium.js,appium.js目录中不能有空格或者(x86)等字样

  10. 构建工具是如何用 node 操作 html/js/css/md 文件的

    构建工具是如何用 node 操作 html/js/css/md 文件的 从本质上来说,html/js/css/md ... 源代码文件都是文本文件,文本文件的内容都是字符串,对文本文件的操作其实就是对 ...

随机推荐

  1. bzoj 3153: Sone1 Toptree

    3153: Sone1 Time Limit: 40 Sec  Memory Limit: 256 MBSubmit: 511  Solved: 202[Submit][Status][Discuss ...

  2. Java RMI远程方法调用

    RMI(远程接口调用) 1. RMI的原理: RMI系统结构,在客户端和服务器端都有几层结构. 方法调用从客户对象经占位程序(Stub).远程引用层(Remote Reference Layer)和传 ...

  3. VS2012中使用纯C实现COM的小问题

    用VS2012新建C++工程都预定义了宏__cplusplus,所以引用到的都是C++的定义.但是要用C实现的话,一般都是也就不是C++的了.比如以下代码: #undef INTERFACE #def ...

  4. How to hide TabPage from TabControl

    No, this doesn't exist. You have to remove the tab and re-add it when you want it. Or use a differen ...

  5. bzoj1444

    显然自动机上高斯消元根据AC自动机上的转移可以列出一系列方程但这个样的方程解出来全0是一组解说明有线性组合的情况考虑除非没人能赢,否则每个人赢的概率和为1那么我们只要把原来的第一个方程换成这个即可 . ...

  6. 20140708郑州培训第二题Impossible Game

    Impossible Game题目描述你发明了一个简单的单人电脑游戏.在开始游戏时,玩家必须输入一个长度为 K 的字符串,且这个字符串的元素只能为‘A’‘B’‘C’或者‘D’.每一种字符串都代表一种颜 ...

  7. 【转】BCSphere入门教程01:Immediate Alert--不错

    原文网址:http://www.ituring.com.cn/article/117570 写在前面 智能硬件开发的起点是智能硬件,在本教程中的每一章节,首先会列出您的蓝牙智能硬件所需要支持的Serv ...

  8. JS日期时间格式化

    Date.prototype.Format = function (fmt) { //author: meizz var o = { "M+": this.getMonth() + ...

  9. Makefile第四讲:include 引用其它makefile文件

    main.cpp #include "classes/fun.h" int main() { Test::display("Hello makefile"); ...

  10. JS思维导图