feature(zip) zip -> zipio

This commit is contained in:
coderaiser 2015-01-23 04:07:12 -05:00
parent 8a3271af4e
commit 71b6ba02a1
10 changed files with 245 additions and 109 deletions

View file

@ -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"
}
}

View file

@ -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);
});
}

View file

@ -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);
}
}
})();

View file

@ -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"
}

35
modules/zipio/.bower.json Normal file
View file

@ -0,0 +1,35 @@
{
"name": "zipio",
"homepage": "https://github.com/coderaiser/zipio",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"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"
}

5
modules/zipio/ChangeLog Normal file
View file

@ -0,0 +1,5 @@
2015.01.23, v1.0.1
fix:
- (zipio) pako

28
modules/zipio/README.md Normal file
View file

@ -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

25
modules/zipio/bower.json Normal file
View file

@ -0,0 +1,25 @@
{
"name": "zipio",
"homepage": "https://github.com/coderaiser/zipio",
"authors": [
"coderaiser <mnemonic.enemy@gmail.com>"
],
"description": "zip data",
"main": "lib/zipio.js",
"moduleType": [
"globals",
"node"
],
"keywords": [
"zip"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"modules"
],
"dependencies": {
"pako": "~0.2.5"
}
}

119
modules/zipio/lib/zipio.js Normal file
View file

@ -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);

View file

@ -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 <mnemonic.enemy@gmail.com> (http://coderaiser.github.io/)",
"license": "MIT",
"bugs": {
"url": "https://github.com/coderaiser/zipio/issues"
},
"homepage": "https://github.com/coderaiser/zipio"
}