node 0.5.0-pre新增功能汇总
发布于 13 年前 作者 qingdu 6705 次浏览 最后一次编辑是 8 年前

近期node社区一直在在热火朝天的完善libuv中. <br/>新功能开发方面的似乎变动不大. <br/>从目前的使用来看,在osx下稳定性还不错.可用度也很高 <br/>窃以为, 已经可以作为开发环境来了. <br/>btw.前几天出了个missing headers files的编译问题 <br/> <br/>这里把v0.5引入的新功能做了各简单的汇总. <br/> <br/><h3>Buffer</h3> <br/><h4>二进制数值读写</h4> <br/><ul> <br/> <li>buffer.readUInt8(offset, endian)</li> <br/> <li>buffer.readUInt16(offset, endian)</li> <br/> <li>buffer.readUInt32(offset, endian)</li> <br/> <li>buffer.readInt8(offset, endian)</li> <br/> <li>buffer.readInt16(offset, endian)</li> <br/> <li>buffer.readInt32(offset, endian)</li> <br/> <li>buffer.readFloat(offset, endian)</li> <br/> <li>buffer.readDouble(offset, endian)</li> <br/> <li>buffer.writeUInt8(value, offset, endian)</li> <br/> <li>buffer.writeUInt16(value, offset, endian)</li> <br/> <li>buffer.writeUInt32(value, offset, endian)</li> <br/> <li>buffer.writeInt8(value, offset, endian)</li> <br/> <li>buffer.writeInt16(value, offset, endian)</li> <br/> <li>buffer.writeInt32(value, offset, endian)</li> <br/> <li>buffer.writeFloat(value, offset, endian)</li> <br/> <li>buffer.writeDouble(value, offset, endian)</li> <br/></ul> <br/><h4>buffer填充</h4> <br/><ul> <br/> <li>buffer.fill(value, offset=0, length=-1)</li> <br/></ul> <br/> <br/><h3>Child Process</h3> <br/><h4>child_process.fork</h4> <br/><p>主进程与子进程简单通信</p> <br/><pre escaped=“true” lang=“javascript” line=“1”> <br/>// master.js <br/>var cp = require(‘child_process’); <br/>var n = cp.fork(__dirname + ‘/child.js’); <br/>n.on(‘message’, function(m) { <br/> console.log(‘PARENT got message:’, m); <br/>}); <br/>n.send({ hello: ‘world’ }); <br/> <br/>// child.js <br/>process.on(‘message’, function(m) { <br/> console.log(‘CHILD got message:’, m); <br/>}); <br/>process.send({ foo: ‘bar’ }); <br/></pre> <br/> <br/><h3>File System</h3> <br/><h4>chown支持</h4> <br/><ul> <br/> <li>fs.chown(path, mode, [callback])</li> <br/> <li>fs.chownSync(path, mode)</li> <br/> <li>fs.fchown(path, mode, [callback])</li> <br/> <li>fs.fchownSync(path, mode)</li> <br/> <li>fs.lchown(path, mode, [callback])</li> <br/> <li>fs.lchownSync(path, mode)</li> <br/></ul> <br/><h4>timestamp修改</h4> <br/><ul> <br/> <li>fs.utimes(path, atime, mtime, callback)</li> <br/> <li>fs.utimesSync(path, atime, mtime)</li> <br/> <li>fs.futimes(path, atime, mtime, callback)</li> <br/> <li>fs.futimesSync(path, atime, mtime)</li> <br/></ul> <br/><h4>fsync支持</h4> <br/><ul> <br/> <li>fs.fsync(fd, callback)</li> <br/> <li>fs.fsyncSync(fd)</li> <br/></ul> <br/><h4>file.writeStream</h4> <br/><p>file.bytesWritten</p> <br/> <br/><h3>Http</h3> <br/><p>http.request与http.getAgent支持unix domain socket</p> <br/> <br/><h3>OS</h3> <br/><ul> <br/> <li>os.platform()</li> <br/> <li>os.arch()</li> <br/> <li>os.release()</li> <br/> <li>os.getNetworkInterfaces()</li> <br/></ul> <br/> <br/><h3>process</h3> <br/><ul> <br/> <li>process.arch</li> <br/> <li>process.uptime()</li> <br/></ul> <br/> <br/><h3>其他</h3> <br/><p>新增对module cache的访问 require.cache</p> <br/><p>新增对主module的访问 require.main</p> <br/><p>新增异步模快定义的支持</p> <br/><pre escaped=“true” lang=“javascript” line=“1”> <br/>define(function (require, exports, module) { <br/> var PI = Math.PI; <br/> exports.area = function ® { <br/> return PI * r * r; <br/> }; <br/> exports.circumference = function ® { <br/> return 2 * PI * r; <br/> }; <br/>}); <br/></pre> <br/>

3 回复

Buffer的二进制读写很赞!NND,之前写个B+ Tree还得自己写pack / unpack函数

~~啊啊啊啊 新手飘过。。

有的看不懂啊,还是要好好学学…

回到顶部