forked from MobileChromeApps/cordova-plugin-zip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzip.js
36 lines (34 loc) · 1.17 KB
/
zip.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
var exec = cordova.require('cordova/exec');
function newProgressEvent(result) {
var event = {
loaded: result.loaded,
total: result.total
};
return event;
}
exports.unzip = function(fileName, outputDirectory, callback, progressCallback) {
var win = function(result) {
if (result && typeof result.loaded != "undefined") {
if (progressCallback) {
return progressCallback(newProgressEvent(result));
}
} else if (callback) {
callback(0);
}
};
var fail = function(result) {
if (callback) {
callback(-1);
}
};
var http2file = function (httpUrl) {
const httpP = "http://localhost/__cdvfile_files__/"
if (-1 == httpUrl.indexOf(httpP)) {
return httpUrl
}
return httpUrl.replace(httpP, cordova.file.dataDirectory)
}
console.log({fileName, outputDirectory, fileNameFile:http2file(fileName), outputDirectoryFile:http2file(outputDirectory), cordova})
exec(win, fail, 'Zip', 'unzip', [http2file(fileName), http2file(outputDirectory)]);
// exec(win, fail, 'Zip', 'unzip', [fileName, outputDirectory]);
};