Outsider | 8 Oct 12:46 2011
Picon

callback in fs.write is not working as document

I asked at stackoverflow.



somebody know about this?
thanks.

--
/************************************************
Outsider
Front-end & Server-side Developer

*************************************************/

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
mscdex | 8 Oct 14:04 2011
Picon

Re: callback in fs.write is not working as document

On Oct 8, 6:46 am, Outsider <outside...@...> wrote:
> somebody know about this?

Only the position should be able to be null. You should fill in the
others and use buffers instead of raw strings.

So instead of:
fs.write(fd, 'test', null, null, null, function(err) {
  /* ... */
});

try:
fs.write(fd, new Buffer('test'), 0, 4, null, function(err) {
  /* ... */
});

--

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@...
To unsubscribe from this group, send email to
nodejs+unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Nicolas Chambrier | 8 Oct 14:09 2011
Picon

Re: Re: callback in fs.write is not working as document

I'd pass undefined instead of null. The typical test is "'undefined' == typeof param", null does not match this test.

Le 8 oct. 2011 14:04, "mscdex" <mscdex-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> a écrit :
On Oct 8, 6:46 am, Outsider <outside...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> somebody know about this?

Only the position should be able to be null. You should fill in the
others and use buffers instead of raw strings.

So instead of:
fs.write(fd, 'test', null, null, null, function(err) {
 /* ... */
});

try:
fs.write(fd, new Buffer('test'), 0, 4, null, function(err) {
 /* ... */
});

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
mscdex | 8 Oct 14:41 2011
Picon

Re: callback in fs.write is not working as document

On Oct 8, 8:09 am, Nicolas Chambrier <naho...@...> wrote:
> I'd pass undefined instead of null. The typical test is "'undefined' ==
> typeof param", null does not match this test.

For fs.write, the check is done in C++ land and simply does an
IsInt32(), so either null or undefined would work.

--

-- 
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs@...
To unsubscribe from this group, send email to
nodejs+unsubscribe@...
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Outsider | 8 Oct 18:20 2011
Picon

Re: Re: callback in fs.write is not working as document

Thank you mscdex..


>fs.write(fd, new Buffer('test'), 0, 4, null, function(err) {
this is working good.

But I little confused.

    fs.write(fd, expected, 0, expected.length, null, function(err, written)


fs.write(fd, expected, 0, 'utf8', function(err, written)

first one has 6 parameters, and second one has 5 parameter.
is it override?? (in javascript??)

and there is only first one in document( http://nodejs.org/docs/v0.4.12/api/fs.html#fs.write )
what different between two cases.


On Sat, Oct 8, 2011 at 9:41 PM, mscdex <mscdex-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
On Oct 8, 8:09 am, Nicolas Chambrier <naho...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> I'd pass undefined instead of null. The typical test is "'undefined' ==
> typeof param", null does not match this test.

For fs.write, the check is done in C++ land and simply does an
IsInt32(), so either null or undefined would work.

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe <at> googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en



--
/************************************************
Outsider
Front-end & Server-side Developer

*************************************************/

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Thomas Shinnick | 8 Oct 21:07 2011
Picon

Re: Re: callback in fs.write is not working as document

From my answer at SO.  (It is not really surprising that some code still uses the older interface definition, and no it is not documented, and that was a mistake)

There was an older interface for fs.write that is still supported. It allowed strings to be written. Because you gave a string instead of a 'Buffer' node tried to make your arguments fit this older interface:

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

Notice that the older interface had 'callback' as the 5th argument. For the fifth argument you gave it 'null' :
fs.write(fd, 'test', null, null, null, function(err) {

node saw 'null' for your callback and so didn't think you had given node a callback.

Either use Buffer data strings as suggested, or use the old interface correctly to use plain strings. If you aren't ready to use Buffer's right now, just use "new Buffer('test')" until you are ready.

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en
Outsider | 8 Oct 22:00 2011
Picon

Re: Re: callback in fs.write is not working as document

I don't know about legacy interface.


really appreciate your answers.
I understand now.

On Sun, Oct 9, 2011 at 4:07 AM, Thomas Shinnick <tshinnic-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
From my answer at SO.  (It is not really surprising that some code still uses the older interface definition, and no it is not documented, and that was a mistake)

There was an older interface for fs.write that is still supported. It allowed strings to be written. Because you gave a string instead of a 'Buffer' node tried to make your arguments fit this older interface:

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

Notice that the older interface had 'callback' as the 5th argument. For the fifth argument you gave it 'null' :

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

node saw 'null' for your callback and so didn't think you had given node a callback.

Either use Buffer data strings as suggested, or use the old interface correctly to use plain strings. If you aren't ready to use Buffer's right now, just use "new Buffer('test')" until you are ready.

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en



--
/************************************************
Outsider
Front-end & Server-side Developer

*************************************************/

--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nodejs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
nodejs+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Gmane