The use and definition of 'end' is likely to be the same as for TypedArray.subarray(start,end) <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray/subarray> or Array.slice(start,end) <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice> where the JS docs are careful to say "end - Element to end at. *The offset is exclusive* (i.e. outside of) If not specified, all elements from the one specified by begin to the end of the array are included in the new view."
So 'end' is the index *just beyond the end* of the area you want to grab. And yes, (end - start) gives you exactly the length to use, *because* end is one past the end of the area you want. As to the other half of your question, don't know... :-( On Friday, December 26, 2014 10:15:50 PM UTC-6, // ravi wrote: > > > 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/d6bcabd9-2390-477d-9e47-bb937d37d729%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
