Howdy all,

humour me another round. My question today:

The writable.end() call takes three arguments: (1) chunk to write if any, (2) 
encoding, (3) callback for when all writing is done.

Assuming there is nothing left to write, I am hoping it is okay to pass null, 
null to the first two arguments.

And I am guessing it is also safe to assume that the end() will be queued up 
after any pending write()s.

With regard to the callback argument, the docs say:

> callback Function Optional. Called when the final chunk is successfully 
> written.

My question is what does “successfully written” really mean? In particular, can 
the callback rely on fs’s file.bytesWritten to have the correct value? The doc 
for the latter says:

> The number of bytes written so far. Does not include data that is still 
> queued for writing.

These two bits suggest the below is safe to do:

req.on
(
    ‘data’,
    function(chunk)
    {
         console.log(“Sending “ + chunk.length + “ bytes to be written.”);
         write_stream.write(chunk);
    }
);

req.on
(
    ‘end’,
    write_stream.end
    (
         null, null,
         function()
         {
             console.log(“Yay, the file is written. Size is “ + 
write_stream.bytesWritten);
         }
    );
);

But in my experience, it does not seem to be. If I send 1000 bytes, the first 
log prints, say, 4 times with 250 byte writes, as expected. But the 
bytesWritten value is much smaller than the 1000 bytes sent (all numbers are 
made up).

I can post more fleshed out sample code if/once you confirm my assumptions are 
correct. I realise there are other ways to do this (e.g: pipe, or listen to the 
‘final’ event for the writeable, etc), but I am curious if the above is even 
expected behaviour.

Thank you,

        —ravi


-- 
-- 
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 [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

--- 
You received this message because you are subscribed to the Google Groups 
"nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to