mirror of
https://github.com/coderaiser/cloudcmd.git
synced 2026-07-18 00:47:01 +00:00
feature(edit) add unzip
This commit is contained in:
parent
8f58774bcb
commit
f7d8bf3b65
15 changed files with 12394 additions and 2 deletions
|
|
@ -171,7 +171,8 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Ace;
|
|||
value = Ace.getValue();
|
||||
|
||||
CloudCmd.getConfig(function(config) {
|
||||
var isDiff = config.diff;
|
||||
var isDiff = config.diff,
|
||||
isZip = config.zip;
|
||||
|
||||
Util.ifExec(!isDiff, function(patch) {
|
||||
var query = '',
|
||||
|
|
@ -187,7 +188,20 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Ace;
|
|||
if (isStr && patch && isLessLength)
|
||||
query = '?patch';
|
||||
|
||||
DOM.RESTful.write(path + query, patch || Value, onSave);
|
||||
Util.ifExec(!isZip || query, function(equal, data) {
|
||||
var result = data || patch || Value,
|
||||
url = path + query;
|
||||
|
||||
DOM.RESTful.write(url, result , onSave);
|
||||
}, function(func) {
|
||||
zip(value, function(error, data) {
|
||||
if (error)
|
||||
Util.log(error);
|
||||
|
||||
query = '?unzip';
|
||||
func(null, data);
|
||||
});
|
||||
});
|
||||
|
||||
}, Util.bind(doDiff, path));
|
||||
});
|
||||
|
|
@ -240,6 +254,20 @@ var CloudCmd, Util, DOM, CloudFunc, ace, DiffProto, diff_match_patch, Ace;
|
|||
});
|
||||
}
|
||||
|
||||
function zip(value, callback) {
|
||||
var dir = CloudCmd.LIBDIRCLIENT,
|
||||
libs = [
|
||||
dir + 'zip/dist/pako.js',
|
||||
dir + 'zip.js'
|
||||
],
|
||||
url = CloudFunc.getJoinURL(libs);
|
||||
|
||||
DOM.jsload(url, function() {
|
||||
Zip.pack(value, callback);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
function load(callback) {
|
||||
var files = [
|
||||
DIR + 'theme-tomorrow_night_blue.js',
|
||||
|
|
|
|||
42
lib/client/zip.js
Normal file
42
lib/client/zip.js
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
var Util, Zip, pako;
|
||||
|
||||
(function () {
|
||||
'use strict';
|
||||
|
||||
Zip = new ZipProto();
|
||||
|
||||
function ZipProto() {
|
||||
this.pack = function(str, callback) {
|
||||
var buf, deflate, result,
|
||||
isArray = Util.isArrayBuffer(str);
|
||||
|
||||
if (isArray)
|
||||
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 = unescape(encodeURIComponent(str)),
|
||||
n = strUtf8.length,
|
||||
arr = new Uint8Array(n);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
arr[i] = strUtf8.charCodeAt(i);
|
||||
|
||||
return arr;
|
||||
}
|
||||
}
|
||||
})();
|
||||
39
lib/client/zip/.bower.json
Normal file
39
lib/client/zip/.bower.json
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
{
|
||||
"name": "pako",
|
||||
"main": "dist/pako.js",
|
||||
"version": "0.1.1",
|
||||
"homepage": "https://github.com/nodeca/pako",
|
||||
"authors": [
|
||||
"Andrei Tuputcyn <Andrew.Tupitsin@gmail.com>",
|
||||
"Vitaly Puzrin <vitaly@rcdesign.ru>"
|
||||
],
|
||||
"description": "deflate / inflate / gzip for bworser - very fast zlib port",
|
||||
"keywords": [
|
||||
"zlib",
|
||||
"deflate",
|
||||
"inflate",
|
||||
"gzip"
|
||||
],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"Makefile",
|
||||
"index*",
|
||||
"lib",
|
||||
"benchmark",
|
||||
"coverage"
|
||||
],
|
||||
"_release": "0.1.1",
|
||||
"_resolution": {
|
||||
"type": "version",
|
||||
"tag": "0.1.1",
|
||||
"commit": "160301218a747105cd5803ab76812b6074dd4399"
|
||||
},
|
||||
"_source": "git://github.com/nodeca/pako.git",
|
||||
"_target": "~0.1.1",
|
||||
"_originalSource": "pako",
|
||||
"_direct": true
|
||||
}
|
||||
77
lib/client/zip/Gruntfile.js
Normal file
77
lib/client/zip/Gruntfile.js
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
'use strict';
|
||||
|
||||
|
||||
module.exports = function(grunt) {
|
||||
var browsers = [{
|
||||
browserName: 'iphone',
|
||||
platform: 'OS X 10.8',
|
||||
version: '6'
|
||||
}, {
|
||||
browserName: 'android',
|
||||
platform: 'Linux',
|
||||
version: '4.0'
|
||||
}, {
|
||||
browserName: 'firefox',
|
||||
platform: 'XP',
|
||||
version: '27'
|
||||
}, {
|
||||
browserName: 'chrome',
|
||||
platform: 'XP',
|
||||
version: '32'
|
||||
}, {
|
||||
browserName: 'internet explorer',
|
||||
platform: 'WIN8',
|
||||
version: '10'
|
||||
}, {
|
||||
browserName: 'internet explorer',
|
||||
platform: 'VISTA',
|
||||
version: '9'
|
||||
}, {
|
||||
browserName: 'internet explorer',
|
||||
platform: 'Windows 7',
|
||||
version: '8'
|
||||
}, {
|
||||
browserName: 'internet explorer',
|
||||
platform: 'XP',
|
||||
version: '7'
|
||||
}, {/*
|
||||
browserName: 'opera',
|
||||
platform: 'Windows 2008',
|
||||
version: '12'
|
||||
}, {*/
|
||||
browserName: 'safari',
|
||||
platform: 'OS X 10.8',
|
||||
version: '6'
|
||||
}];
|
||||
|
||||
|
||||
grunt.initConfig({
|
||||
connect: {
|
||||
server: {
|
||||
options: {
|
||||
base: '',
|
||||
port: 9999
|
||||
}
|
||||
}
|
||||
},
|
||||
'saucelabs-mocha': {
|
||||
all: {
|
||||
options: {
|
||||
urls: ['http://127.0.0.1:9999/test/browser/test.html'],
|
||||
build: process.env.TRAVIS_JOB_ID || ('local' + ~~(Math.random()*1000)),
|
||||
browsers: browsers,
|
||||
testname: process.env.SAUCE_PROJ || 'mocha tests'
|
||||
}
|
||||
}
|
||||
},
|
||||
watch: {}
|
||||
});
|
||||
|
||||
// Loading dependencies
|
||||
for (var key in grunt.file.readJSON('package.json').devDependencies) {
|
||||
if (key !== 'grunt' && key.indexOf('grunt') === 0) { grunt.loadNpmTasks(key); }
|
||||
}
|
||||
|
||||
//grunt.registerTask('dev', ['connect', 'watch']);
|
||||
grunt.registerTask('test', ['connect', 'saucelabs-mocha']);
|
||||
};
|
||||
10
lib/client/zip/HISTORY.md
Normal file
10
lib/client/zip/HISTORY.md
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
0.1.1 / 2014-03-20
|
||||
-------------------
|
||||
|
||||
- Bugfixes for inflate/deflate.
|
||||
|
||||
|
||||
0.1.0 / 2014-03-15
|
||||
-------------------
|
||||
|
||||
- First release.
|
||||
21
lib/client/zip/LICENSE
Normal file
21
lib/client/zip/LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
(The MIT License)
|
||||
|
||||
Copyright (C) 2014 by Vitaly Puzrin
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
137
lib/client/zip/README.md
Normal file
137
lib/client/zip/README.md
Normal file
|
|
@ -0,0 +1,137 @@
|
|||
pako - zlib port to javascript, very fast!
|
||||
==========================================
|
||||
|
||||
[](https://travis-ci.org/nodeca/pako)
|
||||
|
||||
__Why pako is cool:__
|
||||
|
||||
- Almost as fast in modern JS engines as C implementation (see benchmarks).
|
||||
- Works in browsers, you can browserify any separate component.
|
||||
- Both Sync & streamable (for big blobs) interfaces.
|
||||
- It's fresh - ports the latest zlib version (now 1.2.8), results are binary equal.
|
||||
|
||||
This project was done to understand how fast JS can be and is it necessary to
|
||||
develop native C modules for CPU-intensive tasks. Enjoy the result!
|
||||
|
||||
__Benchmarks:__
|
||||
|
||||
```
|
||||
node v0.10.26, 1mb sample:
|
||||
|
||||
deflate-dankogai x 4.74 ops/sec ±0.68% (15 runs sampled)
|
||||
deflate-gildas x 4.61 ops/sec ±1.73% (15 runs sampled)
|
||||
deflate-imaya x 3.10 ops/sec ±3.73% (11 runs sampled)
|
||||
! deflate-pako x 7.11 ops/sec ±0.26% (21 runs sampled)
|
||||
deflate-pako-untyped x 4.34 ops/sec ±1.35% (14 runs sampled)
|
||||
deflate-zlib x 14.34 ops/sec ±2.90% (68 runs sampled)
|
||||
inflate-dankogai x 31.29 ops/sec ±0.72% (56 runs sampled)
|
||||
inflate-imaya x 30.49 ops/sec ±0.84% (53 runs sampled)
|
||||
! inflate-pako x 70.00 ops/sec ±1.60% (71 runs sampled)
|
||||
inflate-pako-untyped x 17.67 ops/sec ±1.27% (33 runs sampled)
|
||||
inflate-zlib x 70.82 ops/sec ±1.69% (81 runs sampled)
|
||||
|
||||
node v0.11.11, 1mb sample:
|
||||
|
||||
deflate-dankogai x 5.61 ops/sec ±0.30% (17 runs sampled)
|
||||
deflate-gildas x 4.97 ops/sec ±5.68% (16 runs sampled)
|
||||
deflate-imaya x 3.53 ops/sec ±4.19% (12 runs sampled)
|
||||
! deflate-pako x 11.52 ops/sec ±0.23% (32 runs sampled)
|
||||
deflate-pako-untyped x 5.12 ops/sec ±1.44% (17 runs sampled)
|
||||
deflate-zlib x 14.33 ops/sec ±3.34% (63 runs sampled)
|
||||
inflate-dankogai x 42.96 ops/sec ±0.19% (57 runs sampled)
|
||||
inflate-imaya x 85.05 ops/sec ±1.07% (71 runs sampled)
|
||||
! inflate-pako x 97.58 ops/sec ±0.69% (80 runs sampled)
|
||||
inflate-pako-untyped x 18.06 ops/sec ±0.65% (56 runs sampled)
|
||||
inflate-zlib x 60.60 ops/sec ±2.04% (67 runs sampled)
|
||||
```
|
||||
|
||||
zlib's test is partialy afferted by marshling (that make sense for inflate only).
|
||||
You can change deflate level to 0 in benchmark source, to investigate details.
|
||||
For deflate level 6 results can be considered as correct.
|
||||
|
||||
__Install:__
|
||||
|
||||
node.js:
|
||||
|
||||
```
|
||||
npm install pako
|
||||
```
|
||||
|
||||
browser:
|
||||
|
||||
```
|
||||
bower install pako
|
||||
```
|
||||
|
||||
|
||||
Example & API
|
||||
-------------
|
||||
|
||||
Full docs - http://nodeca.github.io/pako/
|
||||
|
||||
```javascript
|
||||
var pako = require('pako');
|
||||
|
||||
// Deflate
|
||||
//
|
||||
var input = new Uint8Array();
|
||||
//... fill input data here
|
||||
var output = pako.deflate(input);
|
||||
|
||||
// Inflate (simple wrapper can throw exception on broken stream)
|
||||
//
|
||||
var compressed = new Uint8Array();
|
||||
//... fill data to uncompress here
|
||||
try {
|
||||
var result = pako.inflate(compressed);
|
||||
catch (err) {
|
||||
console.log(err);
|
||||
}
|
||||
|
||||
//
|
||||
// Alternate interface for chunking & without exceptions
|
||||
//
|
||||
|
||||
var inflator = new pako.Inflate();
|
||||
|
||||
inflator.push(chunk1, false);
|
||||
inflator.push(chunk2, false);
|
||||
...
|
||||
inflator.push(chunkN, true); // true -> last chunk
|
||||
|
||||
if (inflator.err) {
|
||||
console.log(inflator.msg);
|
||||
}
|
||||
|
||||
var output = inflator.result;
|
||||
|
||||
```
|
||||
|
||||
|
||||
Notes
|
||||
-----
|
||||
|
||||
Pako does not contain some specific zlib functions:
|
||||
|
||||
- __deflate__ - writing custom gzip headers and methods `deflateSetDictionary`,
|
||||
`deflateParams`, `deflateSetHeader`, `deflateBound`, `deflatePending`.
|
||||
- __inflate__ - getting custom gzip headers and methods `inflateGetDictionary`,
|
||||
`inflateGetHeader`, `inflateSetDictionary`, `inflateSync`, `inflateSyncPoint`,
|
||||
`inflateCopy`, `inflateUndermine`, `inflateMark`.
|
||||
|
||||
|
||||
Authors
|
||||
-------
|
||||
|
||||
- Andrey Tupitsin [@anrd83](https://github.com/andr83)
|
||||
- Vitaly Puzrin [@puzrin](https://github.com/puzrin)
|
||||
|
||||
Personal thanks to Vyacheslav Egorov ([@mraleph](https://github.com/mraleph))
|
||||
for his awesome tutoruals about optimising JS code for v8,
|
||||
[IRHydra](http://mrale.ph/irhydra/) tool and his advices.
|
||||
|
||||
|
||||
License
|
||||
-------
|
||||
|
||||
MIT
|
||||
24
lib/client/zip/bower.json
Normal file
24
lib/client/zip/bower.json
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
{
|
||||
"name": "pako",
|
||||
"main": "dist/pako.js",
|
||||
"version": "0.1.1",
|
||||
"homepage": "https://github.com/nodeca/pako",
|
||||
"authors": [
|
||||
"Andrei Tuputcyn <Andrew.Tupitsin@gmail.com>",
|
||||
"Vitaly Puzrin <vitaly@rcdesign.ru>"
|
||||
],
|
||||
"description": "deflate / inflate / gzip for bworser - very fast zlib port",
|
||||
"keywords": ["zlib", "deflate", "inflate", "gzip"],
|
||||
"license": "MIT",
|
||||
"ignore": [
|
||||
"**/.*",
|
||||
"node_modules",
|
||||
"bower_components",
|
||||
"test",
|
||||
"Makefile",
|
||||
"index*",
|
||||
"lib",
|
||||
"benchmark",
|
||||
"coverage"
|
||||
]
|
||||
}
|
||||
5880
lib/client/zip/dist/pako.js
vendored
Normal file
5880
lib/client/zip/dist/pako.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
3
lib/client/zip/dist/pako.min.js
vendored
Normal file
3
lib/client/zip/dist/pako.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
3351
lib/client/zip/dist/pako_deflate.js
vendored
Normal file
3351
lib/client/zip/dist/pako_deflate.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
2
lib/client/zip/dist/pako_deflate.min.js
vendored
Normal file
2
lib/client/zip/dist/pako_deflate.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
2741
lib/client/zip/dist/pako_inflate.js
vendored
Normal file
2741
lib/client/zip/dist/pako_inflate.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
2
lib/client/zip/dist/pako_inflate.min.js
vendored
Normal file
2
lib/client/zip/dist/pako_inflate.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
35
lib/client/zip/package.json
Normal file
35
lib/client/zip/package.json
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"name" : "pako",
|
||||
"description" : "zlib port to javascript - fast, modularized, with browser support",
|
||||
"version" : "0.1.1",
|
||||
"keywords" : [ "zlib", "deflate", "inflate", "gzip" ],
|
||||
"homepage" : "https://github.com/nodeca/pako",
|
||||
|
||||
"contributors" : [ "Andrei Tuputcyn (https://github.com/andr83)",
|
||||
"Vitaly Puzrin (https://github.com/puzrin)" ],
|
||||
|
||||
"bugs" : { "url": "https://github.com/nodeca/pako/issues" },
|
||||
"license" : { "type": "MIT", "url": "https://github.com/nodeca/pako/blob/master/LICENSE" },
|
||||
"repository" : { "type": "git", "url": "git://github.com/nodeca/pako.git" },
|
||||
|
||||
"main" : "./index.js",
|
||||
|
||||
"devDependencies" : {
|
||||
"mocha": "*",
|
||||
"chai": "*",
|
||||
"benchmark": "*",
|
||||
"ansi": "*",
|
||||
"browserify":"*",
|
||||
"uglify-js": "*",
|
||||
"jshint": "*",
|
||||
"istanbul": "*",
|
||||
"ndoc": "*",
|
||||
"lodash": "2.4.1",
|
||||
"async": "0.2.10",
|
||||
|
||||
"grunt": "~0.4.0",
|
||||
"grunt-cli": "~0.1.13",
|
||||
"grunt-saucelabs": "~5.0.1",
|
||||
"grunt-contrib-connect": "~0.7.1"
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue