在本文中,我们将给您介绍关于nodejs打包exe文件,及压缩zip文件的详细内容,并且为您解答node.js打包exe的相关问题,此外,我们还将为您提供关于bash–(unixshell脚本)解压缩
在本文中,我们将给您介绍关于nodejs 打包exe 文件,及压缩 zip文件的详细内容,并且为您解答node.js打包exe的相关问题,此外,我们还将为您提供关于bash – (unix shell脚本)解压缩多个zip文件,重命名zip文件名下的解压缩文件、exe4j打包exe文件、GPG解密NodeJS中的Zip文件、Java实现先把多个文件压缩为zip文件后下载zip文件的知识。
本文目录一览:- nodejs 打包exe 文件,及压缩 zip文件(node.js打包exe)
- bash – (unix shell脚本)解压缩多个zip文件,重命名zip文件名下的解压缩文件
- exe4j打包exe文件
- GPG解密NodeJS中的Zip文件
- Java实现先把多个文件压缩为zip文件后下载zip文件
nodejs 打包exe 文件,及压缩 zip文件(node.js打包exe)
pkg node.js打包生成exe应用程序 let fs = require("fs");//获取文件系统模块,负责读写文件 2 let path = require("path");//工具模块,处理文件路径的小工具 3 let JSZIP = require("jszip"); 4 let zip = new JSZIP(); 5 6 //读取目录及文件 7 function readDir(obj, nowPath) { 8 let files = fs.readdirSync(nowPath);//读取目录中的所有文件及文件夹(同步操作) 9 files.forEach(function (fileName, index) {//遍历检测目录中的文件 10 console.log(fileName, index);//打印当前读取的文件名 11 let fillPath = nowPath + "/" + fileName; 12 let file = fs.statSync(fillPath);//获取一个文件的属性 13 if (file.isDirectory()) {//如果是目录的话,继续查询 14 let dirlist = zip.folder(fileName);//压缩对象中生成该目录 15 readDir(dirlist, fillPath);//重新检索目录文件 16 } else { 17 obj.file(fileName, fs.readFileSync(fillPath));//压缩目录添加文件 18 } 19 }); 20 } 21 22 //开始压缩文件 23 function startZIP() { 24 var currPath = __dirname;//文件的绝对路径 当前当前js所在的绝对路径 25 var targetDir = path.join(currPath, "JsonMerge"); 26 readDir(zip, targetDir); 27 zip.generateAsync({//设置压缩格式,开始打包 28 type: "nodebuffer",//nodejs用 29 compression: "DEFLATE",//压缩算法 30 compressionOptions: {//压缩级别 31 level: 9 32 } 33 }).then(function (content) { 34 fs.writeFileSync(currPath + "/result.zip", content, "utf-8");//将打包的内容写入 当前目录下的 result.zip中 35 }); 36 } 37 38 startZIP();
bash – (unix shell脚本)解压缩多个zip文件,重命名zip文件名下的解压缩文件
759198298412.zip ----i love you.pdf ----forever and one.txt ----today and tomorrow.docs 48891721241592__5123.zip ----whatever it is.pdf 5717273_616.zip ----igotit.txt ----thank you very much.mp3
我正在尝试制作一个脚本来解压缩zip文件,并将解压缩的文件重命名为zip文件名.喜欢这个输出:
759198298412.pdf 759198298412.txt 759198298412.docs 48891721241592__5123.pdf 5717273_616.txt 5717273_616mp3
我在下面找到了这个脚本,但它对我不起作用,因为我的文件有空间,我在zip文件中有多个文件.
for i in *.zip do n=$(unzip -lqq $i | awk '{print $NF}') e=${n#*.} unzip $i && mv $n ${i%%_*}".$e" done
请帮忙!谢谢
解决方法
for i in *.zip; do mkdir "$i-dir" cd "$i-dir" unzip "../$i" for j in *; do mv "$j" "$i.${j##*.}" done cd .. done
如果在文件名中的第一个下划线之后删除所有内容比mv行应该是重要的:
mv "$j" "${i%%_*}.${j##*.}"
即使zip文件名中没有下划线,也可以使用:
i=${i%.zip}; mv "$j" "${i%%_*}.${j##*.}"
并将文件全部保存在顶级目录前缀../到mv目标文件名.
exe4j打包exe文件
1.首先打jar包,这里记录的是Eclipse版。也可以用studio生成jar包。打开Eclipse,在你想导成jar的文件目录结构右键选择:Export
2.第二步:
2.生成后的jar:
3.打开exe4j,直接:next
选择“JAR in EXE”mode,继续next
填写完后next
直接next
设置最小,最大JRE版本,适情况定,然后点击【Advanced Options】,选择【Search sequence】,将我们的JRE添加到软件中,这样的话,我们的代码可以在别的没有安装Java环境的电脑上运行;
一直next
最后:如果电脑没有JRE环境,需要和jre放在同一目录下才能运行。
GPG解密NodeJS中的Zip文件
如何解决GPG解密NodeJS中的Zip文件?
当前,我正在尝试使用私钥在fs中解密一个zip文件,但是在解压缩时,它为空。使用此软件包:https://www.npmjs.com/package/gpg
const privatekey = fs.readFileSync(
"storage/keys/myinvoice_private.key","utf8"
);
try {
const fileEncrypted = "storage/keys/20191030.zip.gpg";
const fileDecrypted = "storage/keys/20191030.zip";
gpg.importKey(privatekey,[],(success: any,err: any) => {
gpg.decryptToFile(
{
source: fileEncrypted,dest: fileDecrypted,},(err: any,success: any) => {
console.log({ err,success });
}
);
});
return true;
} catch (e) {
return false;
}
};
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Java实现先把多个文件压缩为zip文件后下载zip文件
Java实现请求后台后,多个Excel压缩成一个zip后,再下载zip,下载完删除压缩包。
1、添加依赖
<!-- 下载依赖 -->
<dependency>
<groupId>commons-fileupload</groupId>
<artifactId>commons-fileupload</artifactId>
<version>1.3.2</version>
</dependency>
<!-- servlet的依赖,有就不用 -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
2、DownloadZip下载servlet,servlet
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
public class DownloadZip extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setCharacterEncoding("UTF-8");
//获得要下载的文件名
String fileName = "用户表.xlsx";
String fileName2 = "用户表1.xlsx";
String fileSaveRootPath = "F:\\develop_java\\tomcat\\apache-tomcat-9.0.13\\webapps\\ROOT\\WEB-INF\\classes\\excel\\";
//得到要下载的文件
File file = new File(fileSaveRootPath, fileName);
File file2 = new File(fileSaveRootPath, fileName2);
System.out.println("Excel文件保存路径1:" + fileSaveRootPath + fileName);
System.out.println("Excel文件保存路径2:" + fileSaveRootPath + fileName2);
//如果文件不存在
if (!file.exists() || !file2.exists()) {
request.setAttribute("message", "您要下载的资源已被删除!!");
request.getRequestDispatcher("/message.jsp").forward(request, response);
return;
}
//先压缩
String zipName = "下载Excel.zip";
String zipPath = fileSaveRootPath + zipName;
ZipOutputStream zipOutput = new ZipOutputStream(new BufferedOutputStream(new FileOutputStream(zipPath)));
ZipEntry zEntry = new ZipEntry(file.getName());
zipOutput.putNextEntry(zEntry);
BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
byte[] buffer = new byte[1024];
int read = 0;
while((read = bis.read(buffer)) != -1){
zipOutput.write(buffer, 0, read);
}
zEntry = new ZipEntry(file2.getName());
zipOutput.putNextEntry(zEntry);
bis = new BufferedInputStream(new FileInputStream(file2));
while((read = bis.read(buffer)) != -1){
zipOutput.write(buffer, 0, read);
}
bis.close();
zipOutput.close();
//创建输出流,下载zip
try(OutputStream out = response.getOutputStream();
FileInputStream in = new FileInputStream(new File(zipPath));){
//设置响应头,控制浏览器下载该文件
response.setHeader("Content-Type","application/octet-stream");
response.setHeader("Content-Disposition",
"attachment;filename="+java.net.URLEncoder.encode(zipName, "UTF-8"));
while((read = in.read(buffer)) != -1){
out.write(buffer, 0, read);
}
System.out.println("zip下载路径:"+zipPath);
}finally {
try {
//删除压缩包
File zfile = new File(zipPath);
zfile.delete();
}catch (Exception e){
e.printStackTrace();
}
}
}
}
3、web.xml配置servlet,我这里没有使用框架
<servlet>
<servlet-name>DownloadZip</servlet-name>
<servlet-class>com.gx.zip.DownloadZip</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DownloadZip</servlet-name>
<url-pattern>/servlet/DownloadZip</url-pattern>
</servlet-mapping>
4、downzip.jsp下载jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>下载zip</title>
</head>
<body>
<a href="${pageContext.request.contextPath}/servlet/DownloadZip">下载</a>
</body>
</html>
5、message.jsp没有文件提示jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
${ message }
</body>
</html>
6、测试
http://localhost:8080/downzip.jsp
OK!Thank you for reading!
关于nodejs 打包exe 文件,及压缩 zip文件和node.js打包exe的问题就给大家分享到这里,感谢你花时间阅读本站内容,更多关于bash – (unix shell脚本)解压缩多个zip文件,重命名zip文件名下的解压缩文件、exe4j打包exe文件、GPG解密NodeJS中的Zip文件、Java实现先把多个文件压缩为zip文件后下载zip文件等相关知识的信息别忘了在本站进行查找喔。
本文标签: