|
|
Line 1: |
Line 1: |
| == Binary Data == | | = Proposals = |
|
| |
|
| 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.
| | # [[ServerJS/Binary/A]] Proposal A from Ondras |
| | # [[ServerJS/Binary/B]] Proposal B from Kris Kowal |
|
| |
|
| === Binary() object proposition === | | = Prior Art = |
|
| |
|
| This is an interface of my proposed Binary object. I also created a sample implementation, see http://tmp.zarovi.cz/binary.js.
| | * [http://help.adobe.com/en_US/AIR/1.1/jslr/flash/utils/ByteArray.html Adobe AIR's ByteArray] |
| | * [https://developer.mozilla.org/En/NsIBinaryInputStream Mozilla's nsIBinaryInputStream] |
| | * [https://developer.mozilla.org/En/NsIBinaryOutputStream Mozilla's nsIBinaryOutputStream] |
| | * [http://www.ejscript.org/products/ejs/doc/api/gen/ejscript/intrinsic-ByteArray.html EJScript ByteArray] |
| | * [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] |
|
| |
|
| /**
| | = Relevant Discussions = |
| * Creates a new variable holding binary data.
| |
| * @param {number} initialData Variable amount if initial arguments.
| |
| Every number represents a byte.
| |
| * @returns {Binary}
| |
| */
| |
| function Binary(initialData) {};
| |
|
| |
|
| /**
| | * [http://groups.google.com/group/serverjs/browse_thread/thread/be72ef3d8146731d/06c27162b698eef5?lnk=gst First Proposal] |
| * Returns the number of bytes stored in this structure.
| | * [http://groups.google.com/group/serverjs/browse_thread/thread/da076076c965d069/2cd8ac336387ceb3?lnk=gst Comments on Binary object] |
| * This is intentionally named "getLength" instead of "length" to indicate a method (and not a property).
| | * [http://groups.google.com/group/serverjs/browse_thread/thread/e866544eb3aff182/16ed57b3c78b86e1?lnk=gst Binary API Brouhaha] |
| * @returns {number}
| |
| */
| |
| Binary.prototype.getLength = function() {};
| |
| | |
| /**
| |
| * Converts the binary variable to string by UTF-8 encoding its contents.
| |
| * @returns {string}
| |
| */
| |
| Binary.prototype.toString = function() {};
| |
| | |
| /**
| |
| * 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 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() {};
| |
| | |
| [[User:Ondras|Ondras]] 08:24, 5 February 2009 (UTC)
| |