ServerJS/Binary: Difference between revisions

From MozillaWiki
Jump to navigation Jump to search
 
(8 intermediate revisions by 5 users not shown)
Line 1: Line 1:
== Binary Data ==
JavaScript does not have a binary data type. However, in server-side scenarios, binary data needs to be often processed. That is why we need some working byte or binary array or string class.


JavaScript does not have a binary data type. However, in server-side scenarios, binary data needs to be often processed. That is why we need some working <tt>Binary()</tt> class.
= Proposals =


=== Binary() object proposition ===
# [[ServerJS/Binary/A]] Proposal A from Ondras
# [[ServerJS/Binary/B]] Proposal B from Kris Kowal
# [[ServerJS/Binary/C]] Proposal C from Daniel Friesen


This is an interface of my proposed Binary object. I also created a sample implementation, see [[http://tmp.zarovi.cz/binary.js]].
= Prior Art =


/**
* [http://help.adobe.com/en_US/AIR/1.1/jslr/flash/utils/ByteArray.html Adobe AIR's ByteArray]
  * Creates a new variable holding binary data.
* [https://developer.mozilla.org/En/NsIBinaryInputStream Mozilla's nsIBinaryInputStream]
  * @param {number} initialData Variable amount if intial arguments.  
* [https://developer.mozilla.org/En/NsIBinaryOutputStream Mozilla's nsIBinaryOutputStream]
    Every number represents a byte.
* [http://www.ejscript.org/products/ejs/doc/api/gen/ejscript/intrinsic-ByteArray.html EJScript ByteArray]
  * @returns {Binary}
* [http://code.google.com/apis/gears/api_blob.html Google Gears Blob]
  */
* [http://code.google.com/p/jslibs/wiki/jslang#jslang::Blob_class  JSlibs Blob]
function Binary(initialData) {};
* [http://flusspferd.org/docs/js/Blob Flusspferd Blob] [http://github.com/ruediger/flusspferd/blob/1ead764aca33aca6926b6ac85871d1482c465616/src/core/blob.jsdoc repository link] (since it has been removed, the docs might go away at some point)


/**
= Relevant Discussions =
  * Returns the number of bytes stored in this structure.
  * This is intentionally named "getLength" instead of "length" to indicate a method (and not a property).
  * @returns {number}
  */
Binary.prototype.getLength = function() {};


/**
* [http://groups.google.com/group/serverjs/browse_thread/thread/be72ef3d8146731d/06c27162b698eef5?lnk=gst First Proposal]
  * Converts the binary variable to string by UTF-8 encoding its contents.
* [http://groups.google.com/group/serverjs/browse_thread/thread/da076076c965d069/2cd8ac336387ceb3?lnk=gst Comments on Binary object]
  * @returns {string}
* [http://groups.google.com/group/serverjs/browse_thread/thread/e866544eb3aff182/16ed57b3c78b86e1?lnk=gst Binary API Brouhaha]
  */
* [http://groups.google.com/group/serverjs/browse_thread/thread/f8ad81201f7b121b ByteArray and ByteString proposal] regarding proposal B
Binary.prototype.toString = function() {};


/**
[[ServerJS/Encodings|Encodings]] are a related topic.
  * Returns a byte value from a given index.
  * @param {number} index
  * @returns {number}
  */
Binary.prototype.getByte = function(index) {};
 
/**
  * Sets a byte value at given index.
  * @param {number} index
  */
Binary.prototype.setByte = function(index, value) {};
 
/**
  * These are essentialy copied from the Array class.
  */
Binary.prototype.pop = function() {};
Binary.prototype.push = function() {};
Binary.prototype.shift = function() {};
Binary.prototype.unshift = function() {};
 
/**
  * Encodes the data in Base64
  * @returns {string}
  */
Binary.prototype.base64encode = function() {};
 
/**
  * Calculates MD5 hash
  * @returns {string}
  */
Binary.prototype.md5 = function() {};
 
/**
  * Calculates SHA1 hash
  * @returns {string}
  */
Binary.prototype.sha1 = function() {};
 
/**
  * Decodes Encodes the data in Base64
  * @returns {string}
  */
Binary.prototype.base64encode = function() {};
 
/**
  * Decodes the Base64 encoded string
  * @returns {Binary}
  */
String.prototype.base64decode = function() {};
 
/**
  * Converts an UTF-8 encoded string into its binary (one byte per item) variant
  * @returns {Binary}
  */
String.prototype.toBinary = function() {};

Latest revision as of 22:09, 30 July 2009

JavaScript does not have a binary data type. However, in server-side scenarios, binary data needs to be often processed. That is why we need some working byte or binary array or string class.

Proposals

  1. ServerJS/Binary/A Proposal A from Ondras
  2. ServerJS/Binary/B Proposal B from Kris Kowal
  3. ServerJS/Binary/C Proposal C from Daniel Friesen

Prior Art

Relevant Discussions

Encodings are a related topic.