1
0
Fork 0
js-stream-issue/working.js

23 lines
654 B
JavaScript
Raw Normal View History

2017-02-01 10:45:11 -05:00
const BUCKET = "atomakabucket"
const fs = require("fs")
const unzipper = require("unzipper")
const aws = require("aws-sdk")
aws.config.update({ region: "us-east-1" })
const s3 = new aws.S3()
s3
.getObject({ Bucket: BUCKET, Key: "hello.zip" })
.createReadStream()
.pipe(unzipper.Parse())
.on('entry', file => {
file.pipe(fs.createWriteStream(file.path))
.on('finish', () => {
s3.putObject(
{ Bucket: BUCKET, Key: file.path, Body: fs.createReadStream(file.path) }
).promise()
2017-02-01 10:52:51 -05:00
.then(() => { console.log("success"); fs.unlinkSync("hello.txt") })
2017-02-01 10:45:11 -05:00
.catch(err => console.log(err))
})
})