Promisify stream
This commit is contained in:
parent
36ebb30825
commit
33fa0b50b7
|
@ -123,29 +123,22 @@ module S3Module {
|
||||||
}
|
}
|
||||||
|
|
||||||
async readCsv(query: { bucket: string; key: string }) {
|
async readCsv(query: { bucket: string; key: string }) {
|
||||||
let streamErr: string | undefined = undefined
|
|
||||||
const stream = this.client
|
const stream = this.client
|
||||||
.getObject({
|
.getObject({
|
||||||
Bucket: query.bucket,
|
Bucket: query.bucket,
|
||||||
Key: query.key,
|
Key: query.key,
|
||||||
})
|
})
|
||||||
.createReadStream()
|
.createReadStream()
|
||||||
.on("error", (err: string) => {
|
|
||||||
//stream.destroy()
|
|
||||||
//
|
|
||||||
console.log("err ", err)
|
|
||||||
streamErr = "ERROR"
|
|
||||||
})
|
|
||||||
|
|
||||||
if (streamErr) {
|
return new Promise((resolve, reject) => {
|
||||||
throw new Error("ERROR")
|
stream
|
||||||
}
|
.on("error", (err: Error) => {
|
||||||
|
reject(err)
|
||||||
try {
|
})
|
||||||
return await csv().fromStream(stream)
|
.on("finish", async () => {
|
||||||
} catch (err) {
|
resolve(csv().fromStream(stream))
|
||||||
throw new Error("Failed to read CSV")
|
})
|
||||||
}
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue