Skip to content

Instantly share code, notes, and snippets.

@yannick
Created March 12, 2015 21:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yannick/a7786c662e33741d7136 to your computer and use it in GitHub Desktop.
Save yannick/a7786c662e33741d7136 to your computer and use it in GitHub Desktop.
package main
import (
"bufio"
"bytes"
"compress/gzip"
"fmt"
"github.com/mitchellh/goamz/aws"
"github.com/mitchellh/goamz/s3"
"io"
"log"
"os"
)
func main() {
auth, err := aws.EnvAuth()
if err != nil {
log.Fatal(err)
}
client := s3.New(auth, aws.EUCentral)
bucket := client.Bucket("c1incoming")
content, err := os.Open("testfile2-orig")
defer content.Close()
var b bytes.Buffer
w1 := bufio.NewWriter(&b)
w := gzip.NewWriter(w1)
io.Copy(w, content)
w.Close()
output := bytes.NewReader(b.Bytes())
gzippedSize := int64(b.Len())
log.Printf("having %s bytes in the buffer", gzippedSize)
var headers = map[string][]string{
"Content-Encoding": {"gzip"},
"Content-Type": {"application/text"},
}
err = bucket.PutReaderHeader("test", output, int64(len(b.Bytes())), headers, s3.PublicRead)
if err != nil {
log.Print(err)
}
resp, err := client.ListBuckets()
log.Print(fmt.Sprintf("%T %+v", resp.Buckets[0], resp.Buckets[0]))
}
@yannick
Copy link
Author

yannick commented Mar 12, 2015

how could the transparent gziping be simplyfied?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment