get

package
v2.3.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 22, 2021 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Cmd = &cobra.Command{
	Use:   "get [cid] [output file path]",
	Short: "Get data stored by the user by cid",
	Long:  `Get data stored by the user by cid`,
	Args:  cobra.ExactArgs(2),
	PreRun: func(cmd *cobra.Command, args []string) {
		err := viper.BindPFlags(cmd.Flags())
		c.CheckErr(err)
	},
	Run: func(cmd *cobra.Command, args []string) {
		ctx, cancel := context.WithTimeout(context.Background(), time.Hour*8)
		defer cancel()

		s := spin.New("%s Retrieving specified data...")
		s.Start()

		isFolder := viper.GetBool("folder")
		if isFolder {
			err := c.PowClient.Data.GetFolder(c.MustAuthCtx(ctx), viper.GetString("ipfsrevproxy"), args[0], args[1])
			c.CheckErr(err)
		} else {
			reader, err := c.PowClient.Data.Get(c.MustAuthCtx(ctx), args[0])
			c.CheckErr(err)

			dir := path.Dir(args[1])
			if _, err := os.Stat(dir); os.IsNotExist(err) {
				err = os.MkdirAll(dir, os.ModePerm)
				c.CheckErr(err)
			}
			file, err := os.Create(args[1])
			c.CheckErr(err)

			defer func() { c.CheckErr(file.Close()) }()

			buffer := make([]byte, 1024*32)
			for {
				bytesRead, readErr := reader.Read(buffer)
				if readErr != nil && readErr != io.EOF {
					c.Fatal(readErr)
				}
				_, err = file.Write(buffer[:bytesRead])
				c.CheckErr(err)
				if readErr == io.EOF {
					break
				}
			}
		}
		s.Stop()
		c.Success("Data written to %v", args[1])
	},
}

Cmd is the command.

Functions

This section is empty.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL