我尝试在中测试zip文件的解析节点.js从命令行使用curl。最初,我的路线是这样的:
app.post('/processZip', (req, res) => {
const zip = req.file
console.log(req)
extractCSVFilesFromZip(zip, '/tmp/connections', '/tmp/messages')
const connectionsOutputPath = '/tmp/connections'
const messagesOutputPath = '/tmp/messages'
console.log(`Size of Parsed Connections File: ${connectionsOutputPath.size}`)
console.log(`Size of Parsed Messages File: ${messagesOutputPath.size}`)
res.send('success!')
})
调用如下函数:
const extractCSVFilesFromZip = (zipFilePath, connectionsCSVOutputPath,
messagesCSVOutputPath) => {
console.log(zipFilePath)
fs.createReadStream(zipFilePath)
.pipe(unzip.Parse())
.on('entry', entry => {
const [
fileName,
size
] = [
entry.path,
entry.size
]
if (fileName === 'Connections.csv') {
console.log(`Size of Connections File to Parse: ${size}`)
entry.pipe(fs.createWriteStream(connectionsCSVOutputPath))
} else if (fileName === 'Messages.csv') {
console.log(`Size of Messages File to Parse: ${size}`)
entry.pipe(fs.createWriteStream(messagesCSVOutputPath))
} else {
entry.autodrain()
}
})
}
卷曲-F文件=@../../../Downloads/Basic\u LinkedInDataExport_09-14-2018.zip
http://localhost:5000/processZip/
最初,它给了我一个错误,指向函数中createReadStream的第一个实例,所以我注释掉了所有代码并尝试控制台.log(zipFilePath)查看正在发送的内容。但我还是犯了同样的错误。实际上,我可以注释掉、删除或更改路由或文件中的任何代码,但这没有任何区别。我还是犯了同样的错误。这就好像curl仍然将请求发送到文件的缓存版本,而不处理我所做的更改。但是如果我用sudo nano从命令行检查文件,我可以看到更新的版本。是什么导致了这个问题?我保存了文件,每次都重新启动服务器。可能是我需要比平常等待更长的时间来处理更改,因为它比我习惯使用的代码库更大,或者是其他原因造成的。不管怎样,服务器永远都在运行。提前感谢您的帮助!