feat: support head with --zip (#4219)

This commit is contained in:
Harshavardhana
2022-08-24 23:10:03 -07:00
committed by GitHub
parent 236b50d6db
commit f022a57088
4 changed files with 13 additions and 9 deletions
+3 -3
View File
@@ -45,15 +45,15 @@ var catFlags = []cli.Flag{
},
cli.BoolFlag{
Name: "zip",
Usage: "Extract from remote zip file (MinIO server source only)",
Usage: "extract from remote zip file (MinIO server source only)",
},
cli.Int64Flag{
Name: "offset",
Usage: "Start offset",
Usage: "start offset",
},
cli.Int64Flag{
Name: "tail",
Usage: "Tail number of bytes at ending of file",
Usage: "tail number of bytes at ending of file",
},
}
+2 -2
View File
@@ -145,7 +145,7 @@ func isAliasURLDir(ctx context.Context, aliasURL string, keys map[string][]prefi
}
// getSourceStreamMetadataFromURL gets a reader from URL.
func getSourceStreamMetadataFromURL(ctx context.Context, aliasedURL, versionID string, timeRef time.Time, encKeyDB map[string][]prefixSSEPair) (reader io.ReadCloser,
func getSourceStreamMetadataFromURL(ctx context.Context, aliasedURL, versionID string, timeRef time.Time, encKeyDB map[string][]prefixSSEPair, zip bool) (reader io.ReadCloser,
metadata map[string]string, err *probe.Error,
) {
alias, urlStrFull, _, err := expandAlias(aliasedURL)
@@ -163,7 +163,7 @@ func getSourceStreamMetadataFromURL(ctx context.Context, aliasedURL, versionID s
GetOptions: GetOptions{
SSE: getSSE(aliasedURL, encKeyDB[alias]),
VersionID: versionID,
Zip: false,
Zip: zip,
},
})
}
+7 -3
View File
@@ -47,6 +47,10 @@ var headFlags = []cli.Flag{
Name: "version-id, vid",
Usage: "select an object version to display",
},
cli.BoolFlag{
Name: "zip",
Usage: "extract from remote zip file (MinIO server source only)",
},
}
// Display contents of a file.
@@ -89,7 +93,7 @@ EXAMPLES:
}
// headURL displays contents of a URL to stdout.
func headURL(sourceURL, sourceVersion string, timeRef time.Time, encKeyDB map[string][]prefixSSEPair, nlines int64) *probe.Error {
func headURL(sourceURL, sourceVersion string, timeRef time.Time, encKeyDB map[string][]prefixSSEPair, nlines int64, zip bool) *probe.Error {
var reader io.ReadCloser
switch sourceURL {
case "-":
@@ -97,7 +101,7 @@ func headURL(sourceURL, sourceVersion string, timeRef time.Time, encKeyDB map[st
default:
var err *probe.Error
var metadata map[string]string
if reader, metadata, err = getSourceStreamMetadataFromURL(context.Background(), sourceURL, sourceVersion, timeRef, encKeyDB); err != nil {
if reader, metadata, err = getSourceStreamMetadataFromURL(context.Background(), sourceURL, sourceVersion, timeRef, encKeyDB, zip); err != nil {
return err.Trace(sourceURL)
}
ctype := metadata["Content-Type"]
@@ -199,7 +203,7 @@ func mainHead(ctx *cli.Context) error {
// Convert arguments to URLs: expand alias, fix format.
for _, url := range ctx.Args() {
fatalIf(headURL(url, versionID, timeRef, encKeyDB, ctx.Int64("lines")).Trace(url), "Unable to read from `"+url+"`.")
fatalIf(headURL(url, versionID, timeRef, encKeyDB, ctx.Int64("lines"), ctx.Bool("zip")).Trace(url), "Unable to read from `"+url+"`.")
}
return nil
+1 -1
View File
@@ -310,7 +310,7 @@ func getCSVHeader(sourceURL string, encKeyDB map[string][]prefixSSEPair) ([]stri
default:
var err *probe.Error
var metadata map[string]string
if r, metadata, err = getSourceStreamMetadataFromURL(globalContext, sourceURL, "", time.Time{}, encKeyDB); err != nil {
if r, metadata, err = getSourceStreamMetadataFromURL(globalContext, sourceURL, "", time.Time{}, encKeyDB, false); err != nil {
return nil, err.Trace(sourceURL)
}
ctype := metadata["Content-Type"]