Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

完成日志打印功能 #4

Open
RubyLouvre opened this issue Aug 22, 2012 · 4 comments
Open

完成日志打印功能 #4

RubyLouvre opened this issue Aug 22, 2012 · 4 comments

Comments

@RubyLouvre
Copy link
Owner

没有使用经典的createWriteStream方法,我把要打印的日志push进一个数组,然后hfs.writeFile用递归输出。如果有什么好的实现请告诉我

logger.js

@leizongmin
Copy link

能说说不用createWriteStream而用数组的原因么?

@RubyLouvre
Copy link
Owner Author

因为这样我就省得将字符串转换为Buffer这一步了,也避免了利用流时出现的事件回调套嵌问题

@leizongmin
Copy link

在fs模块中,写到文件时还是要转换成Buffer的

fs.write = function(fd, buffer, offset, length, position, callback) {
  if (!Buffer.isBuffer(buffer)) {
    // legacy string interface (fd, data, position, encoding, callback)
    callback = arguments[4];
    position = arguments[2];

    buffer = new Buffer('' + arguments[1], arguments[3]);
    offset = 0;
    length = buffer.length;
  }

@RubyLouvre
Copy link
Owner Author

……这个以后再改进吧,如果你有什么好补丁,速速提交上来

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants