English 中文(简体)
fs.write不作为文件
原标题:callback in fs.write is not working as document
  • 时间:2011-10-08 10:36:22
  •  标签:
  • node.js

页: 1

f. 标准(fd、缓冲、抵销、长度、位置、[回顾])

So I wrote like:

var fs = require( fs );

fs.open( ./example.txt ,  a , 0666, function(err, fd) {
  if (err) { throw err; }
  console.log( file opened );
  fs.write(fd,  test , null, null, null, function(err) {
    if (err) { throw err; }
    console.log( file written );
    fs.close(fd, function() {
      console.log( file closed );
    });
  });
});

但背书。 没有打字。 产出只是不限的。

fs.write(fd,  test , null, null, function(err) {

but I assign callback for 5th parameter not 6th. this is works. Why defferent with document.

并且,在源头(Node_file.cc)的反馈是6个参数。

 Local<Value> cb = args[5];

我不理解。

最佳回答

旧的奶制品接口仍然得到支持。 该法令允许作书面说明。 因为你给人一个扼杀而不是一个 Bu子,试图使你的论点适合这一老的界面:

fs.write(fd, data, position, encoding, callback)

通知说,旧的界面是第5条论点。 关于第五点,你认为它无效:

fs.write(fd,  test , null, null, null, function(err) {

各位的回击没有结果,因此不认为你已经发出警告。

要么按照建议使用“彩色”数据,要么正确使用旧接口,使用便衣。 如果你现在不准备使用Buffer,那么在你准备就绪之前,就只使用“新的Buffer(试验)”。

问题回答

您需要通过buffer,而不是作为你第二次争辩的示。 此外,还将提出三个论点,而不是一个论点:

var buffer = new Buffer( test );
fs.write(fd, buffer, 0, buffer.length, null, function(err, written, buffer) {

http://nodejs.org/docs/v0.5.8/api/fs.html#fs.write” rel=“nofollow”文件:

f. 标准(fd、缓冲、抵销、长度、位置、[回顾])

fd. 为档案提供书面缓冲。

页: 1

该职位指从档案开始起应写这一数据的抵消部分。 如果职位无效,数据将按目前情况编制。 见pwrite(2)。

反馈意见将分为三个论点(作者、书面、缓冲),其中具体指明从缓冲中写出多少 by。

最后,在请假的电话中,有6 666张是。 UNIX 文档方式





相关问题
How to make Sequelize use singular table names

I have an model called User but Sequelize looks for the table USERS whenever I am trying to save in the DB. Does anyone know how to set Sequelize to use singular table names? Thanks.

What is Node.js? [closed]

I don t fully get what Node.js is all about. Maybe it s because I am mainly a web based business application developer. What is it and what is the use of it? My understanding so far is that: The ...

Clientside going serverside with node.js

I`ve been looking for a serverside language for some time, and python got my attention somewhat. But as I already know and love javascript, I now want learn to code on the server with js and node.js. ...

Can I use jQuery with Node.js?

Is it possible to use jQuery selectors/DOM manipulation on the server-side using Node.js?

How do I escape a string for a shell command in node?

In nodejs, the only way to execute external commands is via sys.exec(cmd). I d like to call an external command and give it data via stdin. In nodejs there does yet not appear to be a way to open a ...

热门标签