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?