S3-gompressor allows getting and putting objects on S3 without worrying about decompression/compression
package main
import (
"github.com/The-Data-Appeal-Company/s3-gompress/client"
"github.com/The-Data-Appeal-Company/gompressors"
"github.com/aws/aws-sdk-go/aws/session"
log "github.com/sirupsen/logrus"
)
func main() {
sess, err := session.NewSessionWithOptions(session.Options{
SharedConfigState: session.SharedConfigEnable,
})
if err != nil {
panic(err)
}
//using gzip as compression/decompression
comp := &gompressors.GzipCompressor{}
s3Client := client.NewS3CompressorClient(sess, "mybucket", comp)
//put
err = s3Client.Put("my/key.gz", []byte("LOL"))
if err != nil {
log.Errorf("oh no! %v", err)
} else {
log.Info("hooray")
}
//get
get, err := s3Client.Get("my/key.gz")
if err != nil {
log.Errorf("oh no! %v", err)
} else {
log.Info("hooray")
}
if string(get) == "LOL" {
log.Info("it works!")
}
//no compression client
s3ClientPlain := client.NewS3PlainClient(sess, "mybucket")
err = s3ClientPlain.Put("my/key", []byte("LOL"))
if err != nil {
log.Errorf("oh no! %v", err)
} else {
log.Info("hooray")
}
}