1 /*--
  2  Copyright 2009-2010 by Stefan Rusterholz.
  3  All rights reserved.
  4  You can choose between MIT and BSD-3-Clause license. License file will be added later.
  5  --*/
  6 
  7 /**
  8  * mixin cc.Codec
  9  */
 10 cc.Codec = {name:'Jacob__Codec'};
 11 
 12 /**
 13  * Unpack a gzipped byte array
 14  * @param {Array} input Byte array
 15  * @returns {String} Unpacked byte string
 16  */
 17 cc.unzip = function () {
 18     return cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, arguments);
 19 };
 20 
 21 /**
 22  * Unpack a gzipped byte string encoded as base64
 23  * @param {String} input Byte string encoded as base64
 24  * @returns {String} Unpacked byte string
 25  */
 26 cc.unzipBase64 = function () {
 27     var tmpInput = cc.Codec.Base64.decode.apply(cc.Codec.Base64, arguments);
 28     return   cc.Codec.GZip.gunzip.apply(cc.Codec.GZip, [tmpInput]);
 29 };
 30 
 31 /**
 32  * Unpack a gzipped byte string encoded as base64
 33  * @param {String} input Byte string encoded as base64
 34  * @param {Number} bytes Bytes per array item
 35  * @returns {Array} Unpacked byte array
 36  */
 37 cc.unzipBase64AsArray = function (input, bytes) {
 38     bytes = bytes || 1;
 39 
 40     var dec = this.unzipBase64(input),
 41         ar = [], i, j, len;
 42     for (i = 0, len = dec.length / bytes; i < len; i++) {
 43         ar[i] = 0;
 44         for (j = bytes - 1; j >= 0; --j) {
 45             ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
 46         }
 47     }
 48     return ar;
 49 };
 50 
 51 /**
 52  * Unpack a gzipped byte array
 53  * @param {Array} input Byte array
 54  * @param {Number} bytes Bytes per array item
 55  * @returns {Array} Unpacked byte array
 56  */
 57 cc.unzipAsArray = function (input, bytes) {
 58     bytes = bytes || 1;
 59 
 60     var dec = this.unzip(input),
 61         ar = [], i, j, len;
 62     for (i = 0, len = dec.length / bytes; i < len; i++) {
 63         ar[i] = 0;
 64         for (j = bytes - 1; j >= 0; --j) {
 65             ar[i] += dec.charCodeAt((i * bytes) + j) << (j * 8);
 66         }
 67     }
 68     return ar;
 69 };
 70 
 71 /**
 72  * string to array
 73  * @param {String} input
 74  * @returns {Array} array
 75  */
 76 cc.StringToArray = function (input) {
 77     var tmp = input.split(","), ar = [], i;
 78     for (i = 0; i < tmp.length; i++) {
 79         ar.push(parseInt(tmp[i]));
 80     }
 81     return ar;
 82 };
 83