>> 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. HTML5+CSS3鼠标悬停图片特效

    点击预览效果            下载该特效: HTML5+CSS3鼠标悬停图片特效.zip 特效说明: 一款HTML5+CSS3鼠标悬停图片事件网页特效,集合了最流行鼠标悬停图片文字.图片动画移动 ...

  2. 《Linux命令行大全》系列(三、Linux 系统)

    在<Linux命令行大全>一书中,第3章名称是 Linux 系统. 概念太大,不过该节内容却是 Linux 系统最为核心的基础——查看 Linux 系统. ls 命令 显示目录自身信息或目 ...

  3. Torch vs Theano

    Torch vs Theano Recently we took a look at Torch 7 and found its data ingestion facilities less than ...

  4. 【Tools】Chrome开发者工具详解

    作为一名前端开发者,打交道最多的可能是和浏览器.市面上各种浏览器多不胜数,主流的有Chrome,Firefox,Safari,IE,Opera,非主流的如360,遨游,QQ浏览器,搜狗浏览器,据说淘宝 ...

  5. IAR ARM、IAR STM8、IAR MSP430共用一个IDE

    转自IAR ARM.IAR STM8.IAR MSP430共用一个IDE 试了安装好多个不同版本不同编译器的IAR,终于明白不同编译器的IAR共用IDE的条件,把几个不同编译器的IAR安装在一起,共用 ...

  6. lubuntu安装maven

    原文转自:jobar.iteye.com/blog/1776747 1 apt-cache search maven 获取所有可用的maven包 2 sudo apt-get install mave ...

  7. php 返回json 解析 报Wide character in print

    php 返回json: zabbix:/var/www/html/DEVOPS/Home/Lib/Action# vim EquipmentAction.class.php <?php head ...

  8. ArrayList集合排序

    using System;using System.Collections;using System.Collections.Generic;using System.Text; namespace ...

  9. BZOJ2464: 中山市选[2009]小明的游戏

    2464: 中山市选[2009]小明的游戏 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 280  Solved: 124[Submit][Statu ...

  10. jboss项目迁移至WebLogic12

    1 weblogic 使用jtds-1.2.3.jar驱动链接MS SQL Server 2008的数据源配置 1.1 拷贝jtds-1.2.3.jar至D:\Oracle\Middleware\wl ...