I am currently writing an API to unzip files to the web browser sandbox filesystem. I have a basic need to pass a parameter to a function that in turn is itself passed as a parameter. Here is some code to illustrate the issue:
//Request a permanent filesystem quota to unzip the catalog.
function requestFilesystem(size){
window.webkitStorageInfo.requestQuota(PERSISTENT, size*1024*1024, function(grantedBytes) {
window.requestFileSystem(PERSISTENT, grantedBytes, function(fs) {
filesystem = fs;
removeRecursively(filesystem.root, unzip(url), onerror);
}, onerror);
}, function(e) {
console.log('Error', e);
});
}
//unzip method can be changed, API remains the same.
//URL of zip file
//callback oncomplete
function unzip(URL) {
importZipToFilesystem(URL, function(){
console.log("Importing Zip - Complete!");
});
}
//remove removeRecursively a folder from the FS
function removeRecursively(entry, onend, onerror) {
var rootReader = entry.createReader();
console.log("Remove Recursive"+entry.fullPath);
rootReader.readEntries(function(entries) {
var i = 0;
function next() {
i++;
removeNextEntry();
}
function removeNextEntry() {
var entry = entries[i];
if (entry) {
if (entry.isDirectory)
removeRecursively(entry, next, onerror);
if (entry.isFile)
entry.remove(next, onerror);
} else
onend();
**Uncaught TypeError: undefined is not a function**
}
removeNextEntry();
}, onerror);
}
If I try to use
function removeRecursively(entry, onend(URL), onerror) {
there is an error, ao my issue is how to pass around the URL value for the unzip function, this unzip function is used as a callback function on the onsuccess of removeRecursively
unzip, don't call it directly.removeRecursively(filesystem.root, unzip, onerror);notremoveRecursively(filesystem.root, unzip(url), onerror);. Also, writingfunction removeRecursively(entry, onend(URL), onerror) {makes no sense at all, how could you execute inside a param list?