Something that never got settled in my head and was discussed a little
in irc was bbuf[i] = Blob([1,2,3]); Does it trim down to the first,
throw an error, replace later bytes, or insert?
Also another discussed idea was the idea of some sort of subsec or range
function for memcopy to make it more readable, easier to remember, and
consistent.
I'll use .range() to describe, but leave the actual name up to
discussion and a show of hands.
seq.range(4,5); would roughly return: { sequence: this, start: 5, end: 5 };
Basically it's a dead simple object (like opaque cookie) used only by
buffer operations to make memcopy possible.
bufB.append(seq); // append all of seq onto bufB `bufB.copy(seq,
bufB.length, seq.length);`
bufB.append(seq.range(2,6)); // append 2-6 of seq onto the end of bufB
`bufB.copy(seq, bufB.length, 6-2, 2)`
bufB.insert(bufA.range(4,7), 5); // insert 4-7 of bufA into bufB at 5
`bufB.copy(bufA, 6, 7-4, 4);`
...
To be honest I find long methods with a bunch of numeric params like
.copy and .splice confusing. I almost always end up referring back to
documentation to make use of them. This is a nice way to keep numbers
relevant to the data they subsect and make memcopy possible.
--
~Daniel Friesen (Dantman, Nadir-Seen-Fire) [http://daniel.friesen.name]
I agree that number args can be confusing because the 2nd number can
mean two things:
| blob.range(4,5) | could mean either of the following things:
blob.range({from: 4, to: 5});
blob.range({from: 4, len: 5});
Perhaps we should start using the form of X.func(optionsObj) in more
places?
I'm not commenting on the usefulness or suitability of anything right
now - my head just isn't in the right place to think properly.
Which is why i suggest using named arguments: There is no scope for
ambiguity as to what it means.
> bufB.append(seq);
> // append all of seq onto bufB
> `bufB.copy(seq, bufB.length, seq.length);`
> bufB.append(seq.range(2,6));
> // append 2-6 of seq onto the end of bufB
> `bufB.copy(seq, bufB.length, 6-2, 2)`
> bufB.insert(bufA.range(4,7), 5);
> // insert 4-7 of bufA into bufB at 5
> `bufB.copy(bufA, 6, 7-4, 4);`
The notation seems equitable. range(begin, end) and range(end) are
intuitive to me. So is range(begin, end, step), but that is perhaps
not applicable in this case. I don't think we should specify that it
be an object literal of that particular interface. Perhaps really an
implementation-specific opaque cookie so we are free to experiment for
a while.
Kris Kowal