minio/docs/extensions/s3zip/examples/minio-go/main.go
Anis Elleuch ba5fb2365c
feat: support of ZIP list/get/head as S3 extension (#12267)
When enabled, it is possible to list/get files
inside a zip file without uncompressing it.

Signed-off-by: Anis Elleuch <anis@min.io>
2021-06-10 08:17:03 -07:00

46 lines
933 B
Go

package main
import (
"context"
"io"
"log"
"net/http"
"os"
"github.com/minio/minio-go/v7"
"github.com/minio/minio-go/v7/pkg/credentials"
)
type s3ExtensionTransport struct {
tr http.RoundTripper
}
func (t *s3ExtensionTransport) RoundTrip(req *http.Request) (*http.Response, error) {
req.Header.Add("x-minio-extract", "true")
return t.tr.RoundTrip(req)
}
func main() {
tr, _ := minio.DefaultTransport(false)
s3Client, err := minio.New("minio-server-address:9000", &minio.Options{
Creds: credentials.NewStaticV4("access-key", "secret-key", ""),
Transport: &s3ExtensionTransport{tr},
})
if err != nil {
log.Fatalln(err)
}
// Download API.md from the archive
rd, err := s3Client.GetObject(context.Background(), "your-bucket", "path/to/file.zip/data.csv", minio.GetObjectOptions{})
if err != nil {
log.Fatalln(err)
}
_, err = io.Copy(os.Stdout, rd)
if err != nil {
log.Fatalln(err)
}
return
}