使用柏树解压缩文件
我需要使用'解压缩'解压缩文件,而我正在使用以下代码进行相同的操作,但是它部分解剖了,但是它会抛出无效的路径错误(因为路径包含特殊字符 *)请帮助我对其进行修复
let path = 'cypress/downloads/'
let file = '910-00001.1-20220419-1843.zip'
describe('example unzip', () => {
it(' test', () => {
cy.task('unzipping', { path, file })
})
//task code (Added it into plugins --> index.js)
const unzipping = require('./unzipping')
module.exports = (on, config) => {
on('task', {
'unzipping': unzipping.unzip,
})
}
// ./unzipping文件(创建一个名为unzipping.js的文件中的插件文件夹)
const decompress = require('decompress');
const unzip = ({ path, file }) => decompress(path + file, path + 'unzip/' + file.replace('.zip', ''))
module.exports = {
unzip,
}
I need to unzip the file using 'unzipping' whereas I am using the below code to do the same but it is partially unzipping but it is throwing an Invalid path error (as path contains special character *).please help me to fix it
let path = 'cypress/downloads/'
let file = '910-00001.1-20220419-1843.zip'
describe('example unzip', () => {
it(' test', () => {
cy.task('unzipping', { path, file })
})
//task code (Added it into plugins --> index.js)
const unzipping = require('./unzipping')
module.exports = (on, config) => {
on('task', {
'unzipping': unzipping.unzip,
})
}
// ./unzipping file (created a file named unzipping.js inside plugin folder)
const decompress = require('decompress');
const unzip = ({ path, file }) => decompress(path + file, path + 'unzip/' + file.replace('.zip', ''))
module.exports = {
unzip,
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,我尝试了您上面提供的所有代码,并且效果很好。
我唯一能想到的是邮政编码的内容是问题。在我的测试中,我用两个文本文件
1.txt
和2.txt
进行了一个简单的邮政编码,然后运行测试,在文件夹/cypress/下载/UNZIP/910-00001.1-20220419-1843
。我建议您使用虚拟邮政编码执行同样的操作,如果代码工作起作用,请查看
910-00001.1-20220419-1843.zip
的内容。So, I tried all your code you gave above, and it worked perfectly.
The only thing I can think if is the contents of the zip is the problem. In my test I made a simple zip with two text files
1.txt
and2.txt
, then running the test, found them in the folder/cypress/downloads/unzip/910-00001.1-20220419-1843
.I suggest you do the same with a dummy zip, if the code works then look at the contents of
910-00001.1-20220419-1843.zip
.