Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Cmd = &cobra.Command{ Use: "download", Short: "Download an object to a local file", RunE: func(cmd *cobra.Command, args []string) error { ctx := cmd.Context() did := strings.TrimSpace(downloadDID) if did == "" { return fmt.Errorf("--did is required") } c, err := cliauth.NewServerClient(cmd) if err != nil { return err } outPath := strings.TrimSpace(downloadOut) var expectedSize int64 if outPath == "" { rec, err := c.Index().Get(ctx, did) if err != nil { return fmt.Errorf("resolve output filename from record: %w", err) } name := did if rec.FileName != nil { if pretty := common.DownloadFilename(*rec.FileName); pretty != "" { name = pretty } } if rec.Size != nil { expectedSize = *rec.Size } outPath = name } else { rec, err := c.Index().Get(ctx, did) if err == nil && rec.Size != nil { expectedSize = *rec.Size } } if err := os.MkdirAll(filepath.Dir(outPath), 0o755); err != nil { return fmt.Errorf("create output directory: %w", err) } fmt.Fprintf(cmd.OutOrStdout(), "Downloading %s -> %s", did, outPath) if expectedSize > 0 { fmt.Fprintf(cmd.OutOrStdout(), " (%s)", syupload.FormatSize(expectedSize)) } fmt.Fprintln(cmd.OutOrStdout()) progress := transferprogress.New(cmd.OutOrStdout(), filepath.Base(outPath), expectedSize) progress.Start() downloadCtx := transferprogress.WithProgress(ctx, did, progress) if err := transferdownload.DownloadFile(downloadCtx, c.Data(), did, outPath); err != nil { progress.Abort() return err } progress.Finish() fmt.Fprintf(cmd.OutOrStdout(), "downloaded %s -> %s\n", did, outPath) return nil }, }
Functions ¶
This section is empty.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.