40
edits
No edit summary |
No edit summary |
||
Line 78: | Line 78: | ||
;blob.length; | ;blob.length; | ||
:Returns the length of the blob. This is immutable. | :Returns the length of the blob. This is immutable. | ||
;blob.contentConstructor; | |||
:Returns Blob to indicate this has binary content. | |||
;blob[index]; // Optional | ;blob[index]; // Optional | ||
Line 124: | Line 127: | ||
:This method is optional, it should be included if the interpreter being used supports .toSource() on it's various objects and types. | :This method is optional, it should be included if the interpreter being used supports .toSource() on it's various objects and types. | ||
:Returns a representation of the blob in the format "(Blob([]))" or "(new Blob([]))". If the blob has content in it the string should contain integers 0..255 representing the blob such that if evaluated (calling the correct Blob function) would return a blob with the same content. | :Returns a representation of the blob in the format "(Blob([]))" or "(new Blob([]))". If the blob has content in it the string should contain integers 0..255 representing the blob such that if evaluated (calling the correct Blob function) would return a blob with the same content. | ||
=== Unpacking === | === Unpacking === | ||
Line 220: | Line 220: | ||
:* In a BlobBuffer this returns a Blob which matches the contents of the buffer. | :* In a BlobBuffer this returns a Blob which matches the contents of the buffer. | ||
:* In a StringBuffer this returns a String which matches the contents of the buffer. | :* In a StringBuffer this returns a String which matches the contents of the buffer. | ||
=== String extensions === | === String extensions === | ||
These extensions may be optional, however it would be ideal if implementations added these prototypes to the standard objects. Implementations may chose how to implement these (load binary themselves beforehand, prototype methods that use require('binary') within them, etc...) | These extensions may be optional, however it would be ideal if implementations added these prototypes to the standard objects. Implementations may chose how to implement these (load binary themselves beforehand, prototype methods that use require('binary') within them, etc...) | ||
;string.contentConstructor; | |||
:Returns String to indicate this has text content. | |||
;string.toBlob(toCharset); | ;string.toBlob(toCharset); | ||
Line 238: | Line 238: | ||
:The point of this prototype is so that (string or blob).codeAt(index); may be used independently of whether the sequence is a string or a blob. This will allow strings to maintain .charCodeAt and blobs to maintain .byteCodeAt without returning unintuitive results. | :The point of this prototype is so that (string or blob).codeAt(index); may be used independently of whether the sequence is a string or a blob. This will allow strings to maintain .charCodeAt and blobs to maintain .byteCodeAt without returning unintuitive results. | ||
; | == Abstract API == | ||
One of the primary focuses was interoperability between Strings and Blobs so that abstract algorithms could be written which work on either strings or blobs. | |||
The entire Buffer api was designed for this purpose, and the following methods on String and Blob are usable in abstract programming: | |||
* seq.length; | |||
* seq.contentConstructor (can be used as seq.contentConstructor() to return an empty seq of the same type) | |||
* seq.valueAt(idx); // Sequence at index | |||
* seq.codeAt(idx); // Number at index | |||
* seq.valueOf(); // Returns the same seq (on a buffer returns the equiv Blob or String) | |||
* seq.indexOf(seq, [off]); and seq.lastIndexOf(seq, [off]); // finding the location of a subsequence | |||
* seq.concat(...seq); // combining sequences together | |||
* seq.slice(begin, end); // extracting a portion of a sequence | |||
* seq.split(sep, [limit]); // split up a sequence using another sequence as a separator | |||
== General requirements == | == General requirements == |
edits