Commit f8b2ab59 authored by Giannis Kopanas's avatar Giannis Kopanas
Browse files

fix(server): remove writing file and use streams

parent 115ad059
Pipeline #19019 canceled with stage
......@@ -5,6 +5,7 @@
/* eslint-disable no-restricted-syntax */
/* eslint-disable no-await-in-loop */
const config = require('config')
const stream = require('stream')
const path = require('path')
const Zip = require('adm-zip')
const fs = require('fs')
......@@ -52,20 +53,32 @@ class ExtractFiles {
`Download file from ftp for parsing: ${this.entity.remoteFolderPath}/${val.data.remoteFiles} ${val.data.id}`,
)
const a = []
const lowCaseTransform = await new stream.Transform()
// eslint-disable-next-line no-underscore-dangle
lowCaseTransform._transform = async (fileChunk, encoding, callback) => {
a.push(Buffer.from(fileChunk))
callback()
}
await this.service.receive(
`/tmp/${filename}`,
lowCaseTransform,
`${this.entity.remoteFolderPath}/${val.data.remoteFiles}`,
)
lowCaseTransform.pipe(process.stdout)
logger.kafka(`Unzip file : /tmp/${filename} ${val.data.id}`)
this.files[val.data.id] = await this.unzipFile(`/tmp/${filename}`)
// console.log(readStream, 'unzip it')
this.files[val.data.id] = await this.unzipFile(Buffer.concat(a))
logger.kafka(
`Delete file from tmp folder: /tmp/${filename} ${val.data.id}`,
)
// logger.kafka(
// `Delete file from tmp folder: /tmp/${filename} ${val.data.id}`,
// )
fs.unlinkSync(`/tmp/${filename}`)
// fs.unlinkSync(`/tmp/${filename}`)
await this.categorizeFiles(val.data.id)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment