Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return unlink(filePath).then(() => {
// password for the dropbox sample zip file
const password = 'helloworld'
return zipWithPassword(
filePath.split('.').slice(0, -1).join('.'),
filePath,
password
).then((response) => {
console.log('Successfully archived the folder')
console.log(response)
}).catch((err) => {
console.log(err)
})
}).catch((err) => {
console.log(err)
this.task = RNFetchBlob.config({
fileCache: true,
appendExt: 'zip',
key: zipUrl,
path: downloadPath,
}).fetch('GET', zipUrl, {
referer: 'http://www.pixiv.net',
});
try {
this.setState({
isDownloadingZip: true,
});
const res = await this.task;
if (!this.unmounting) {
try {
const path = await unzip(res.path(), ugoiraPath);
this.setState({
ugoiraPath: path,
isDownloadingZip: false,
});
// remove zip file after extracted
res.flush();
} catch (err) {
this.setState({
isDownloadingZip: false,
});
}
}
} catch (err) {
this.setState({
isDownloadingZip: false,
});
const { area, layerId, layerUrl, zoom } = config;
const url = `${Config.API_URL}/download-tiles/${area.geostore.id}/${zoom.start}/${
zoom.end
}?layerUrl=${layerUrl}&useExtension=false`;
const res = await RNFetchBlob.config({ fileCache: true })
.fetch('GET', encodeURI(url))
.progress((received, total) => {
const progress = received / total;
dispatch({ type: UPDATE_PROGRESS, payload: { areaId: area.id, progress, layerId } });
});
const statusCode = res.info().status;
if (statusCode >= 200 && statusCode < 400 && res.path()) {
const downloadPath = res.path();
const tilesPath = `${CONSTANTS.files.tiles}/${area.id}/${layerId}`;
const targetPath = `${RNFetchBlob.fs.dirs.DocumentDir}/${tilesPath}`;
await unzip(downloadPath, targetPath);
res.flush(); // remove from the cache
return `${tilesPath}/{z}x{x}x{y}`;
}
throw new Error(`Fetch blob error ${statusCode}`);
}
unzipFiles(res) {
unzip(res.path(), `${DIR.DocumentDir}`).then(() => {
this.loadQuestionsToDB();
AsyncStorageHelper.set('leetcode.unzip', 'true');
}).catch((err) => {
console.log(`解压失败 ${err}`);
Toast.show(`解压失败 ${err}`);
});
}
componentDidMount () {
this.unzipProgress = subscribe(({ progress, filePath }) => {
console.log('---- Progress update ----')
console.log(filePath + ': ' + progress)
console.log('-------------------------')
})
}
}).then((isEncrypted) => {
if (isEncrypted) {
return unzipWithPassword(filePath, unzipPath, password)
} else {
return unzip(filePath, unzipPath)
}
}).then((response) => {
console.log('Successfully unzipped files')
export const unzipNamedIssueArchive = (zipFilePath: string) => {
const outputPath = FSPaths.issuesDir
return unzip(zipFilePath, outputPath).then(() => {
return RNFetchBlob.fs.unlink(zipFilePath)
})
}
unzip (path) {
return unzip(path, DOCUMENTS_FOLDER)
.then(unzippedPath => {
let name
if (this.props.source.unzippedFolderName) {
name = this.props.source.unzippedFolderName
} else {
name = this.getName(path)
name = name.includes('.zip') ? name.replace('.zip', '') : name
}
return `${unzippedPath}/${name}`
})
}
export const unzipNamedIssueArchive = (zipFilePath: string) => {
const outputPath = FSPaths.issuesDir
return unzip(zipFilePath, outputPath).then(() => {
return RNFetchBlob.fs.unlink(zipFilePath)
})
}
* - If it does exists, unzip it & parse the index-v1.json file inside.
* - Else, parse the old index.xml file.
*/
const repoUUID = RNFetchBlob.base64.encode(baseUrl).replace('=', '');
const dlPath = RNFetchBlob.fs.dirs.DownloadDir + '/' + sanitizeUrl(baseUrl);
const indexJarPath = dlPath + '/index-v1.jar';
const responseV1 = await RNFetchBlob.config({ path: indexJarPath }).fetch(
'GET',
baseUrl + '/index-v1.jar'
);
let repoData = null;
const exists = await RNFetchBlob.fs.exists(indexJarPath);
if (exists && responseV1.info().status === 200) {
const jsonPath = await unzip(indexJarPath, dlPath);
const jsonData = await RNFetchBlob.fs.readFile(jsonPath + '/index-v1.json', 'utf8');
repoData = parseRepoIndexV1(jsonData, repoUUID, baseUrl);
await RNFetchBlob.fs.unlink(dlPath);
} else {
const response = await RNFetchBlob.fetch('GET', baseUrl + '/index.xml');
const responseXml = await response.text();
const doc = parser.parseFromString(responseXml);
repoData = parseOldRepoIndex(doc, repoUUID, baseUrl);
}
if (repoData !== null) {
cacheParsedRepo(baseUrl, repoData, CACHE_KEY);
return { success: true, meta: repoData.meta, applications: repoData.applications };
}
return { success: false, error: 'Unknown error, cannot fetch repository ' + baseUrl };