From 71b6ba02a1ba0af4c12b18aa86b7cf5aa25a81c8 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Fri, 23 Jan 2015 04:07:12 -0500 Subject: [PATCH] feature(zip) zip -> zipio --- bower.json | 4 +- lib/client/edward.js | 8 +-- lib/client/zip.js | 99 ------------------------------ modules/load/.bower.json | 5 +- modules/zipio/.bower.json | 35 +++++++++++ modules/zipio/ChangeLog | 5 ++ modules/zipio/README.md | 28 +++++++++ modules/zipio/bower.json | 25 ++++++++ modules/zipio/lib/zipio.js | 119 +++++++++++++++++++++++++++++++++++++ modules/zipio/package.json | 26 ++++++++ 10 files changed, 245 insertions(+), 109 deletions(-) delete mode 100644 lib/client/zip.js create mode 100644 modules/zipio/.bower.json create mode 100644 modules/zipio/ChangeLog create mode 100644 modules/zipio/README.md create mode 100644 modules/zipio/bower.json create mode 100644 modules/zipio/lib/zipio.js create mode 100644 modules/zipio/package.json diff --git a/bower.json b/bower.json index 26e95a7a..c83c319f 100644 --- a/bower.json +++ b/bower.json @@ -24,9 +24,9 @@ "fancybox": "~2.1.5", "jquery": "~2.1.3", "menu": "~0.7.5", - "pako": "~0.2.5", "daffy": "~1.0.1", "jsSHA": "~1.5.0", - "load": "~1.1.2" + "load": "~1.1.2", + "zipio": "~1.0.1" } } diff --git a/lib/client/edward.js b/lib/client/edward.js index 1438b054..93d7fffe 100644 --- a/lib/client/edward.js +++ b/lib/client/edward.js @@ -1,4 +1,4 @@ -var join, ace, load, Util, DOM, CloudCmd, Diff, io, Zip, Format, restafary; +var join, ace, load, Util, DOM, Diff, io, Format, restafary; (function(global, join, DOM, exec, loadRemote) { 'use strict'; @@ -388,11 +388,9 @@ var join, ace, load, Util, DOM, CloudCmd, Diff, io, Zip, Format, restafary; } function zip(value, callback) { - var dir = CloudCmd.LIBDIRCLIENT, - url = dir + 'zip.js'; - exec.parallel([ function(callback) { + var url = DIR + 'zipio/lib/zipio.js'; DOM.load.js(url, callback); }, function(callback) { @@ -402,7 +400,7 @@ var join, ace, load, Util, DOM, CloudCmd, Diff, io, Zip, Format, restafary; if (error) alert(error); else - Zip.pack(value, callback); + global.zipio(value, callback); }); } diff --git a/lib/client/zip.js b/lib/client/zip.js deleted file mode 100644 index da45ce7b..00000000 --- a/lib/client/zip.js +++ /dev/null @@ -1,99 +0,0 @@ -var Util, Zip, pako; - -(function () { - 'use strict'; - - var UTF8 = new UTF8Proto(); - - Zip = new ZipProto(); - - function ZipProto() { - this.pack = function(str, callback) { - var buf, deflate, result, - isArrayBuffer = Util.type.arrayBuffer(str); - - if (isArrayBuffer) - buf = str; - else - buf = utf8AbFromStr(str); - - deflate = new pako.Deflate({ - gzip:true - }); - - deflate.push(buf, true); - - if (!deflate.error) - result = deflate.result.buffer; - - Util.exec(callback, deflate.error, result); - }; - - function utf8AbFromStr(str) { - var i, - strUtf8 = UTF8.unescape(encodeURIComponent(str)), - n = strUtf8.length, - arr = new Uint8Array(n); - - for (i = 0; i < n; i++) - arr[i] = strUtf8.charCodeAt(i); - - return arr; - } - } - - function UTF8Proto() { - /*jshint nonstandard:true */ - var isUnescape = typeof unescape === 'function', - func = isUnescape ? unescape : decode; - - this.unescape = func; - } - - /* - * unescape polyfill - * http://unixpapa.com/js/querystring.html - */ - - function decode(s) { - s = s.replace(/%([EF][0-9A-F])%([89AB][0-9A-F])%([89AB][0-9A-F])/gi, ef) - .replace(/%([CD][0-9A-F])%([89AB][0-9A-F])/gi, cd) - .replace(/%([0-7][0-9A-F])/gi, o7); - - return s; - - function o7(code, hex) { - return String.fromCharCode(parseInt(hex,16)); - } - - function ef(code, hex1, hex2, hex3) { - var n, n3, - n1 = parseInt(hex1,16) - 0xE0, - n2 = parseInt(hex2,16) - 0x80; - - if (n1 === 0 && n2 < 32) - return code; - - n3 = parseInt(hex3,16)-0x80; - n = (n1<<12) + (n2<<6) + n3; - - if (n > 0xFFFF) - return code; - - return String.fromCharCode(n); - } - - function cd(code, hex1, hex2) { - var n1, n2; - - n1 = parseInt(hex1,16) - 0xC0; - - if (n1 < 2) - return code; - - n2 = parseInt(hex2,16) - 0x80; - - return String.fromCharCode((n1<<6) + n2); - } - } -})(); diff --git a/modules/load/.bower.json b/modules/load/.bower.json index 9844eddc..ec1f58c6 100644 --- a/modules/load/.bower.json +++ b/modules/load/.bower.json @@ -22,7 +22,6 @@ "commit": "a888f78f5634e8b93b98863d51ab530957413fbc" }, "_source": "git://github.com/coderaiser/load.js.git", - "_target": "~1.1.3", - "_originalSource": "load", - "_direct": true + "_target": "~1.1.2", + "_originalSource": "load" } \ No newline at end of file diff --git a/modules/zipio/.bower.json b/modules/zipio/.bower.json new file mode 100644 index 00000000..e052a1a7 --- /dev/null +++ b/modules/zipio/.bower.json @@ -0,0 +1,35 @@ +{ + "name": "zipio", + "homepage": "https://github.com/coderaiser/zipio", + "authors": [ + "coderaiser " + ], + "description": "zip data", + "main": "lib/zipio.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "zip" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "modules" + ], + "dependencies": { + "pako": "~0.2.5" + }, + "version": "1.0.1", + "_release": "1.0.1", + "_resolution": { + "type": "version", + "tag": "v1.0.1", + "commit": "605053168a5e774e0f771f2bbea30fa6ef9f23df" + }, + "_source": "git://github.com/coderaiser/zipio.git", + "_target": "~1.0.0", + "_originalSource": "zipio" +} \ No newline at end of file diff --git a/modules/zipio/ChangeLog b/modules/zipio/ChangeLog new file mode 100644 index 00000000..e84ff6e7 --- /dev/null +++ b/modules/zipio/ChangeLog @@ -0,0 +1,5 @@ +2015.01.23, v1.0.1 + +fix: +- (zipio) pako + diff --git a/modules/zipio/README.md b/modules/zipio/README.md new file mode 100644 index 00000000..ec9da4d9 --- /dev/null +++ b/modules/zipio/README.md @@ -0,0 +1,28 @@ +Zipio +===== + +Zip data + +## Install + +``` +npm install zipio --save +bower install zipio --save +``` + +## Use + +```js +var zipio = require('zipio'); + +zipio('hello world', function(error, data) { + if (error) + console.log(error.message); + else + console.log(data): +}); + +``` +## License + +MIT diff --git a/modules/zipio/bower.json b/modules/zipio/bower.json new file mode 100644 index 00000000..94df00f4 --- /dev/null +++ b/modules/zipio/bower.json @@ -0,0 +1,25 @@ +{ + "name": "zipio", + "homepage": "https://github.com/coderaiser/zipio", + "authors": [ + "coderaiser " + ], + "description": "zip data", + "main": "lib/zipio.js", + "moduleType": [ + "globals", + "node" + ], + "keywords": [ + "zip" + ], + "license": "MIT", + "ignore": [ + "**/.*", + "node_modules", + "modules" + ], + "dependencies": { + "pako": "~0.2.5" + } +} diff --git a/modules/zipio/lib/zipio.js b/modules/zipio/lib/zipio.js new file mode 100644 index 00000000..bc74882d --- /dev/null +++ b/modules/zipio/lib/zipio.js @@ -0,0 +1,119 @@ +var pako; + +(function (global) { + 'use strict'; + + if (typeof module !== 'undefined' && module.exports) { + module.exports = new ZipProto(); + pako = require('pako'); + } else { + global.zipio = new ZipProto(); + } + + function ZipProto() { + var UTF8 = new UTF8Proto(); + + function zipio(str, callback) { + var buf, deflate, result, + isArrayBuffer = type(str) === 'arrayBuffer'; + + if (!callback) + throw(Error('callback could not be empty!')); + + if (isArrayBuffer) + buf = str; + else + buf = utf8AbFromStr(str); + + deflate = new pako.Deflate({ + gzip:true + }); + + deflate.push(buf, true); + + if (!deflate.error) + result = deflate.result.buffer; + + callback(deflate.error, result); + } + + function utf8AbFromStr(str) { + var i, + strUtf8 = UTF8.unescape(encodeURIComponent(str)), + n = strUtf8.length, + arr = new Uint8Array(n); + + for (i = 0; i < n; i++) + arr[i] = strUtf8.charCodeAt(i); + + return arr; + } + + function type(variable) { + var regExp = new RegExp('\\s([a-zA-Z]+)'), + str = {}.toString.call(variable), + typeBig = str.match(regExp)[1], + result = typeBig.toLowerCase(); + + return result; + } + + return zipio; + } + + function UTF8Proto() { + /*jshint nonstandard:true */ + var isUnescape = typeof unescape === 'function', + func = isUnescape ? unescape : decode; + + this.unescape = func; + + /* + * unescape polyfill + * http://unixpapa.com/js/querystring.html + */ + + function decode(s) { + s = s.replace(/%([EF][0-9A-F])%([89AB][0-9A-F])%([89AB][0-9A-F])/gi, ef) + .replace(/%([CD][0-9A-F])%([89AB][0-9A-F])/gi, cd) + .replace(/%([0-7][0-9A-F])/gi, o7); + + return s; + + function o7(code, hex) { + return String.fromCharCode(parseInt(hex,16)); + } + + function ef(code, hex1, hex2, hex3) { + var n, n3, + n1 = parseInt(hex1,16) - 0xE0, + n2 = parseInt(hex2,16) - 0x80; + + if (n1 === 0 && n2 < 32) + return code; + + n3 = parseInt(hex3,16)-0x80; + n = (n1<<12) + (n2<<6) + n3; + + if (n > 0xFFFF) + return code; + + return String.fromCharCode(n); + } + + function cd(code, hex1, hex2) { + var n1, n2; + + n1 = parseInt(hex1,16) - 0xC0; + + if (n1 < 2) + return code; + + n2 = parseInt(hex2,16) - 0x80; + + return String.fromCharCode((n1<<6) + n2); + } + } + } + +})(this); diff --git a/modules/zipio/package.json b/modules/zipio/package.json new file mode 100644 index 00000000..e8ec8d73 --- /dev/null +++ b/modules/zipio/package.json @@ -0,0 +1,26 @@ +{ + "name": "zipio", + "version": "1.0.1", + "description": "zip data", + "main": "lib/zipio.js", + "dependencies": { + "pako": "~0.2.5" + }, + "devDependencies": {}, + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "repository": { + "type": "git", + "url": "git://github.com/coderaiser/zipio" + }, + "keywords": [ + "zip" + ], + "author": "coderaiser (http://coderaiser.github.io/)", + "license": "MIT", + "bugs": { + "url": "https://github.com/coderaiser/zipio/issues" + }, + "homepage": "https://github.com/coderaiser/zipio" +}