<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>注意力</title>
<style>
html,
body {
100%;
height: 100%;
}
</style>
</head>
<body>
</body>
<script src="../src/js/lib/jquery.min.js"></script>
<script src="../src/js/global.js"></script>
<script>
var http = require('http');
var fs = require('fs');
var request = require('request');
var unzip = require('unzip');
/*---- 下载解压包 ----*/
var download = function (uri, filename, callback) {
request.head(uri, function (err, res, body) {
console.log('content-type:', res.headers['content-type']);
console.log('content-length:', res.headers['content-length']);
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
download('http://ddd1.pc6.com/soft/jfsky.com-msicuu.rar', 'upload/src/a.rar', function () {
console.log('done');
});
/*---- 解压 ---*/
var extract = unzip.Extract({
path: 'upload/b/a'
});
extract.on('error', function () {
console.log("解压失败");
});
extract.on('finish', function () {
console.log("解压成功");
/* 判断文件夹是否存在 */
fs.exists("upload/b/a", function (exists) {
if (exists) {
console.log("文件夹存在");
/* 重命名文件夹 */
fs.rename('upload/b/a', 'upload/b/c', function (err) {
if (err) {
console.log("重命名失败");
} else {
console.log("重命名成功");
/* 删除文件夹 */
fs.rmdir('upload/b/a', function (err) {
if (err) {
console.log("删除失败");
} else {
console.log("删除成功");
}
});
}
});
} else {
console.log("文件夹不存在");
}
});
});
fs.createReadStream('upload/src/a.zip').pipe(extract);
/* 读取文件 获取应用中的版本号 */
fs.readFile("package.json", function (err, res) {
if (err) throw err;
/* console.log(JSON.parse(res.toString())); */
});
console.log("执行结束");
</script>
</html>