Created
March 12, 2015 21:14
-
-
Save yannick/a7786c662e33741d7136 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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])) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
how could the transparent gziping be simplyfied?