ServerJS/Binary/C: Difference between revisions

no edit summary
m (grammar, spelling, active voice, some clarifications in the introduction)
No edit summary
Line 95: Line 95:
:Combines the content of multiple blobs together and returns a new blob.
:Combines the content of multiple blobs together and returns a new blob.


;blob.slice(offset, length);
;blob.slice(begin, end);
:Extracts a section of the blob and returns a new blob containing it as the contents. (This should behave the same as string.slice and array.slice)
:Extracts a section of the blob and returns a new blob containing it as the contents. (This should behave the same as string.slice and array.slice)


Line 119: Line 119:
:Returns an array containing the decoded Unicode code points.  
:Returns an array containing the decoded Unicode code points.  


;blob.toSource();
: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.
=== Unpacking ===
::''These methods are related to unpacking. They will likely be removed from this proposal but are here for reference until we write a proposal for unpacking of binary data.''
;blob.integerAt(offset, size=1, signed=false, networkEndian=false);
;blob.integerAt(offset, size=1, signed=false, networkEndian=false);
:Extracts an integer out of a blob. Arguments may control the byte size extracted whether the number is signed or unsigned, and whether or not the byte is in networkEndian or not. The default is to return a single unsigned byte in the form of an integer in the range 0..255.
:Extracts an integer out of a blob. Arguments may control the byte size extracted whether the number is signed or unsigned, and whether or not the byte is in networkEndian or not. The default is to return a single unsigned byte in the form of an integer in the range 0..255.
Line 127: Line 133:
;blob.stringAt(offset, size, fromCharset=UTF-16);
;blob.stringAt(offset, size, fromCharset=UTF-16);
:Extracts a string out from a blob. This method is similar to if you had done <code>blob.slice(offset, size).toString(fromCharset||"UTF-16");</code>.
:Extracts a string out from a blob. This method is similar to if you had done <code>blob.slice(offset, size).toString(fromCharset||"UTF-16");</code>.
;blob.toSource();
: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.


=== Buffer ===
=== Buffer ===
Line 170: Line 172:
:Insert a chunk of data into a buffer growing it by <code>data.length</code> and shifting the data to the right of the specified index towards the end of the buffer.
:Insert a chunk of data into a buffer growing it by <code>data.length</code> and shifting the data to the right of the specified index towards the end of the buffer.


;buf.clear(offset, length);
;buf.clear(start, length);
:Zero out a section of the buffer. Binary buffers have bytes replaced with 0 bytes and text buffers have characters replaced with '\0' (null characters).
:Zero out a section of the buffer. Binary buffers have bytes replaced with 0 bytes and text buffers have characters replaced with '\0' (null characters).


40

edits