ServerJS/Binary

From MozillaWiki
< ServerJS
Revision as of 07:54, 5 February 2009 by Ondras (talk | contribs) (New page: == 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 <tt>Binary()</t...)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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 Binary() class.

Binary() object proposition

This is an interface of my proposed Binary object.

/**
 * Creates a new variable holding binary data.
 * @param {number} initialData Variable amount if intial arguments. 
   Every number represents a byte.
 * @returns {Binary}
 */
function Binary(initialData) {};
/**
 * 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 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() {};