ServerJS/Binary/B: Difference between revisions

Added notes section
(→‎Specification: add some results from the discussion)
(Added notes section)
 
(5 intermediate revisions by 3 users not shown)
Line 38: Line 38:
; join(array, delimiter)
; join(array, delimiter)
: Like Array.prototype.join, but for Binarys. Returns a ByteString.
: Like Array.prototype.join, but for Binarys. Returns a ByteString.
(TODO: clarify usage)


=== Instance properties ===
=== Instance properties ===
Line 140: Line 142:
; toString()
; toString()
: A string debug representation like "[ByteArray 10]". Alternative debug representations are valid too, as long as (1) this method will never fail, (2) the length is included.
: A string debug representation like "[ByteArray 10]". Alternative debug representations are valid too, as long as (1) this method will never fail, (2) the length is included.
; decodeToString()
; decodeToString(charset)
; decodeToString(charset)
: returns a String from its decoded bytes in a given charset.  If no charset is provided, or if the charset is "undefined", assumes the default system encoding.
: returns a String from its decoded bytes in a given charset.
; toByteArray()
; toByteArray()
: just a copy
: just a copy
Line 182: Line 183:
; <u>split()</u>  
; <u>split()</u>  
: Returns an array of ByteArrays instead of ByteStrings.
: Returns an array of ByteArrays instead of ByteStrings.
; <u>filter()/u>
; <u>filter(callback[, thisObject])</u>
:
:
; <u>forEach()/u>
; <u>forEach(callback[, thisObject])</u>
:
:
; <u>every()/u>
; <u>every(callback[, thisObject])</u>
:
:
; <u>some()/u>
; <u>some(callback[, thisObject])</u>
:
:
; <u>map()/u>
; <u>map(callback[, thisObject])</u>
:
:
; <u>reduce()/u>
; <u>reduce(callback[, initialValue])</u>
:
:
; <u>reduceRight()/u>
; <u>reduceRight(callback[, initialValue])</u>
:
:
; <u>displace(begin, end, values/ByteStrings/ByteArrays/Arrays...) -> length</u>
; <u>displace(begin, end, values/ByteStrings/ByteArrays/Arrays...) -> length</u>
Line 232: Line 233:


<u>Charsets are case insensitive.</u>
<u>Charsets are case insensitive.</u>
= Tests =
* [http://github.com/tlrobinson/narwhal/tree/master/tests/serverjs ServerJS tests] compatible with [http://github.com/tlrobinson/narwhal/tree/master/lib/test this test framework].
= Notes =
* The '''indexOf''' and '''lastIndexOf''' methods described in this proposal should most definitely be able to handle a Binary object as first argument, like the corresponding String method, which also takes a String as argument. Being able to only search for single bytes seriously constrains the usefulness of these classes.
* Calling ByteString methods '''charAt''' and '''charCodeAt''' when they only return single bytes is misguiding and not good practice. The [[ServerJS/Binary/C|Binary/C]] proposal defines a new '''valueAt''' method that is an alias for '''charAt''' on strings and for '''byteAt''' on blobs.
* Having some common API with Strings and Arrays is certainly a good idea, but do we really have to replicate each and every method? For example, do we really need '''slice''', '''substr''' and '''substring''' on the ByteString, or wouldn't slice alone suffice?


= Relevant Discussions =
= Relevant Discussions =
55

edits