Skip to content

Commit

Permalink
feat: support head with --zip (minio#4219)
Browse files Browse the repository at this point in the history
  • Loading branch information
harshavardhana authored and adfost committed Oct 28, 2022
1 parent b6d7f49 commit 3428d0f
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 9 deletions.
6 changes: 3 additions & 3 deletions cmd/cat-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}

Expand Down
4 changes: 2 additions & 2 deletions cmd/common-methods.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
},
})
}
Expand Down
10 changes: 7 additions & 3 deletions cmd/head-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -89,15 +93,15 @@ 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 "-":
reader = os.Stdin
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"]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cmd/sql-main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down

0 comments on commit 3428d0f

Please sign in to comment.