Howdy all,
please tell me what I am missing here. The doc
(http://nodejs.org/api/buffer.html#buffer_buf_slice_start_end) for Buffer#slice
says:
=========
buf.slice([start], [end])
• start Number, Optional, Default: 0
• end Number, Optional, Default: buffer.length
Returns a new buffer which references the same memory as the old, but offset
and cropped by the start (defaults to 0) and end (defaults to buffer.length)
indexes.
=========
Given that offsets are 0-indexed and [end] is the end offset, shouldn’t that
default to buffer.length - 1? Digging through node/lib/buffer.js to smalloc, I
see:
size_t length = end - start;
i.e., the ‘end’ is not really used as an offset of the end, in calculating the
length. So I am guessing the underlying implementation is safe (which it would
be given Buffer is not new!), so if I am at all right, this is a documentation
*interpretation* issue?
—ravi
P.S: given that the new buffer references the same memory, I am assuming this
is an extremely cheap operation. True?
--
Job board: http://jobs.nodejs.org/
New group rules:
https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules:
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 unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/nodejs/DCC7421E-D167-4088-9A58-74239820E84D%40g8o.net.
For more options, visit https://groups.google.com/d/optout.