當前位置: 首頁>>代碼示例>>Golang>>正文


Golang Node.Download方法代碼示例

本文整理匯總了Golang中github.com/MG-RAST/Shock/shock-client/lib.Node.Download方法的典型用法代碼示例。如果您正苦於以下問題:Golang Node.Download方法的具體用法?Golang Node.Download怎麽用?Golang Node.Download使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/MG-RAST/Shock/shock-client/lib.Node的用法示例。


在下文中一共展示了Node.Download方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: downloadChunk

func downloadChunk(n lib.Node, opts lib.Opts, filename string, offset int64, c chan int) {
	oh, err := os.OpenFile(filename, os.O_RDWR, 0644)
	if err != nil {
		fmt.Printf("Error open output file %s: %s\n", filename, err.Error())
	}
	defer oh.Close()

	_, err = oh.Seek(offset, os.SEEK_SET)
	if err != nil {
		fmt.Printf("Error seek output file %s: %s\n", filename, err.Error())
	}

	if ih, err := n.Download(opts); err != nil {
		fmt.Printf("Error downloading %s: %s\n", n.Id, err.Error())
	} else {
		if s, err := io.Copy(oh, ih); err != nil {
			fmt.Printf("Error writing output: %s\n", err.Error())
		} else {
			fmt.Printf("Success. Wrote %d bytes\n", s)
		}
	}
	c <- 1
}
開發者ID:narayandesai,項目名稱:Shock,代碼行數:23,代碼來源:util.go

示例2: main


//.........這裏部分代碼省略.........
	case "pcreate":
		pcreate(args)

	case "get":
		if len(args) != 1 {
			helpf("get requires <id>")
		}
		n := lib.Node{Id: args[0]}
		if err := n.Get(); err != nil {
			fmt.Printf("Error retrieving %s: %s\n", n.Id, err.Error())
		} else {
			n.PP()
		}
	case "download":
		if len(args) < 1 {
			helpf("download requires <id>")
		}
		index := conf.Flags["index"]
		parts := conf.Flags["parts"]
		indexOptions := conf.Flags["index_options"]
		opts := lib.Opts{}
		if ne(index) || ne(parts) || ne(indexOptions) {
			if ne(index) && ne(parts) {
				opts["index"] = (*index)
				opts["parts"] = (*parts)
				if ne(indexOptions) {
					opts["index_options"] = (*indexOptions)
				}
			} else {
				helpf("index and parts options must be used together")
			}
		}
		n := lib.Node{Id: args[0]}
		if ih, err := n.Download(opts); err != nil {
			fmt.Printf("Error downloading %s: %s\n", n.Id, err.Error())
		} else {
			if len(args) == 3 {
				if oh, err := os.Create(args[1]); err == nil {
					if s, err := io.Copy(oh, ih); err != nil {
						handleString(fmt.Sprintf("Error writing output: %s\n", err.Error()))
					} else {
						fmt.Printf("Success. Wrote %d bytes\n", s)
					}
				} else {
					handleString(fmt.Sprintf("Error writing output: %s\n", err.Error()))
				}
			} else {
				io.Copy(os.Stdout, ih)
			}
		}
	case "pdownload":
		if len(args) < 1 {
			helpf("pdownload requires <id>")
		}
		n := lib.Node{Id: args[0]}
		if err := n.Get(); err != nil {
			handleString(fmt.Sprintf("Error retrieving %s: %s\n", n.Id, err.Error()))
		}

		totalChunk := int(n.File.Size / conf.CHUNK_SIZE)
		m := n.File.Size % conf.CHUNK_SIZE
		if m != 0 {
			totalChunk += 1
		}
		if totalChunk < 1 {
			totalChunk = 1
開發者ID:MG-RAST,項目名稱:Shock,代碼行數:67,代碼來源:shock-client.go

示例3: main

func main() {
	args := flag.Args()
	if *conf.Examples {
		helpf("Coming soon.")
	}
	if len(args) == 0 {
		helpf("")
	}

	switch args[0] {
	case "create", "update":
		n := lib.Node{}
		if args[0] == "update" {
			if len(args) != 2 {
				helpf("update requires <id>")
			} else {
				n.Id = args[1]
			}
		}
		opts := lib.Opts{}
		if ne(conf.Flags["attributes"]) {
			opts["attributes"] = (*conf.Flags["attributes"])
		}
		if t, err := fileOptions(conf.Flags); err != nil {
			helpf(err.Error())
		} else {
			if t == "part" {
				if args[0] == "create" {
					helpf("part option only usable with update")
				}
				if !ne(conf.Flags["file"]) {
					helpf("part option requires file")
				}
				opts["upload_type"] = t
				opts["part"] = (*conf.Flags["part"])
				opts["file"] = (*conf.Flags["file"])
				if err := n.Update(opts); err != nil {
					fmt.Printf("Error updating %s: %s\n", n.Id, err.Error())
				} else {
					n.PP()
				}
			} else {
				if t != "" {
					opts["upload_type"] = t
					opts[t] = (*conf.Flags[t])
					if args[0] == "create" {
						if err := n.Create(opts); err != nil {
							fmt.Printf("Error creating node: %s\n", err.Error())
						} else {
							n.PP()
						}
					} else {
						if err := n.Update(opts); err != nil {
							fmt.Printf("Error updating %s: %s\n", n.Id, err.Error())
						} else {
							n.PP()
						}
					}
				} else {
					if err := n.Create(opts); err != nil {
						fmt.Printf("Error creating node: %s\n", err.Error())
					} else {
						n.PP()
					}
				}
			}
		}
	case "get":
		if len(args) != 2 {
			helpf("get requires <id>")
		}
		n := lib.Node{Id: args[1]}
		if err := n.Get(); err != nil {
			fmt.Printf("Error retrieving %s: %s\n", n.Id, err.Error())
		} else {
			n.PP()
		}
	case "download":
		if len(args) < 2 {
			helpf("download requires <id>")
		}
		index := conf.Flags["index"]
		parts := conf.Flags["parts"]
		indexOptions := conf.Flags["index_options"]
		opts := lib.Opts{}
		if ne(index) || ne(parts) || ne(indexOptions) {
			if ne(index) && ne(parts) {
				opts["index"] = (*index)
				opts["parts"] = (*parts)
				if ne(indexOptions) {
					opts["index_options"] = (*indexOptions)
				}
			} else {
				helpf("index and parts options must be used together")
			}
		}
		n := lib.Node{Id: args[1]}
		if ih, err := n.Download(opts); err != nil {
			fmt.Printf("Error downloading %s: %s\n", n.Id, err.Error())
		} else {
//.........這裏部分代碼省略.........
開發者ID:eberroca,項目名稱:Shock,代碼行數:101,代碼來源:shock-client.go


注:本文中的github.com/MG-RAST/Shock/shock-client/lib.Node.Download方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。