日期:2014-05-16 浏览次数:20473 次
本文是对nodejs0.8.9版本的api开发手册解读.nodejs网址
缓存类(Buffer)
stability:3 - Stable
纯javascript对Unicode支持不叫不错,但是对二进制数据的支持就不怎么样了,当需要处理TCP流或者文件系统时,是必须要处理八进制流(octet streams).Node有几种策略来操作,创建,销毁八进制值流.
原始数据被储存在buffer类的实例中,一个buffer很想一个integer的数组,但是符合一个在v8堆栈外的原始内存分配.一个buffer是不能被改变大小的.
buffer类是全局的,尽量不要一有需要就使用require('buffer')加载.
在buffers和javascript string对象之间转换需要显示的调用一个编码函数.下面是string类型不懂的编码格式:
'ascii' -
for 7 bit ASCII data only. This encoding method is very fast, and will strip the high bit if set. Note that this encoding converts a null character ('\0' or '\u0000')
into 0x20 (character code of a space). If you want to convert a null character into 0x00,
you should use 'utf8'.
'utf8' -
Multibyte encoded Unicode characters. Many web pages and other document formats use UTF-8.多字节编码的Unicode字符.很多web页面和其他文档都使用UTF-8格式.
'utf16le' -
2 or 4 bytes, l