mirror of
https://github.com/minio/minio.git
synced 2025-11-10 22:10:12 -05:00
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>
This commit is contained in:
31
docs/extensions/s3zip/examples/aws-js/main.js
Normal file
31
docs/extensions/s3zip/examples/aws-js/main.js
Normal file
@@ -0,0 +1,31 @@
|
||||
|
||||
var AWS = require('aws-sdk');
|
||||
|
||||
var s3 = new AWS.S3({
|
||||
accessKeyId: 'YOUR-ACCESSKEYID' ,
|
||||
secretAccessKey: 'YOUR-SECRETACCESSKEY' ,
|
||||
endpoint: 'http://127.0.0.1:9000' ,
|
||||
s3ForcePathStyle: true,
|
||||
signatureVersion: 'v4'
|
||||
});
|
||||
|
||||
// List all contents stored in the zip archive
|
||||
s3.listObjectsV2({Bucket : 'your-bucket', Prefix: 'path/to/file.zip/'}).
|
||||
on('build', function(req) { req.httpRequest.headers['X-Minio-Extract'] = 'true'; }).
|
||||
send(function(err, data) {
|
||||
if (err) {
|
||||
console.log("Error", err);
|
||||
} else {
|
||||
console.log("Success", data);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
// Download a file in the archive and store it in /tmp/data.csv
|
||||
var file = require('fs').createWriteStream('/tmp/data.csv');
|
||||
s3.getObject({Bucket: 'your-bucket', Key: 'path/to/file.zip/data.csv'}).
|
||||
on('build', function(req) { req.httpRequest.headers['X-Minio-Extract'] = 'true'; }).
|
||||
on('httpData', function(chunk) { file.write(chunk); }).
|
||||
on('httpDone', function() { file.end(); }).
|
||||
send();
|
||||
|
||||
8
docs/extensions/s3zip/examples/aws-js/package.json
Normal file
8
docs/extensions/s3zip/examples/aws-js/package.json
Normal file
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "s3-zip-example",
|
||||
"version": "1.0.0",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"aws-sdk": "^2.924.0"
|
||||
}
|
||||
}
|
||||
25
docs/extensions/s3zip/examples/boto3/main.py
Normal file
25
docs/extensions/s3zip/examples/boto3/main.py
Normal file
@@ -0,0 +1,25 @@
|
||||
#!/usr/bin/env/python
|
||||
|
||||
import boto3
|
||||
from botocore.client import Config
|
||||
|
||||
s3 = boto3.client('s3',
|
||||
endpoint_url='http://localhost:9000',
|
||||
aws_access_key_id='YOUR-ACCESSKEYID',
|
||||
aws_secret_access_key='YOUR-SECRETACCESSKEY',
|
||||
config=Config(signature_version='s3v4'),
|
||||
region_name='us-east-1')
|
||||
|
||||
|
||||
def _add_header(request, **kwargs):
|
||||
request.headers.add_header('x-minio-extract', 'true')
|
||||
event_system = s3.meta.events
|
||||
event_system.register_first('before-sign.s3.*', _add_header)
|
||||
|
||||
# List zip contents
|
||||
response = s3.list_objects_v2(Bucket="your-bucket", Prefix="path/to/file.zip/")
|
||||
print(response)
|
||||
|
||||
# Downlaod data.csv stored in the zip file
|
||||
s3.download_file(Bucket='your-bucket', Key='path/to/file.zip/data.csv', Filename='/tmp/data.csv')
|
||||
|
||||
45
docs/extensions/s3zip/examples/minio-go/main.go
Normal file
45
docs/extensions/s3zip/examples/minio-go/main.go
Normal file
@@ -0,0 +1,45 @@
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user