Skip to content

Latest commit

 

History

History
159 lines (134 loc) · 5.42 KB

README.tw.md

File metadata and controls

159 lines (134 loc) · 5.42 KB

curl - 使用 Go語言 編寫的 多任務下載器

Build Status Version Gowalker Godoc Gitter Slack Jianliao

curl 是使用 Go語言 編寫的 多任務下載器,可以下載:二進位( exe, jpg ),文本文件( txt, json )等多種格式。

Multi-download

文檔

English | 繁體中文

支持

  • Mac OS
  • Linux
  • Windows ( usage kernel32.dll and SetConsoleCursorPosition function )

安裝

go get -u github.com/Kenshin/curl

使用

import "github.com/Kenshin/curl"

入門指南

逐行讀取文本
// curl.Get
code, res, _ := curl.Get("http://npm.taobao.org/mirrors/node/latest/SHASUMS256.txt")
if code != 0 {
    return
}

// close
defer res.Body.Close()

// parse callback
processFunc := func(content string, line int) bool {
    fmt.Printf("line is %v, content is %v", line, content)
    return false
}

// read line
if err := ReadLine(res.Body, processFunc); err != nil && err != io.EOF {
    fmt.Println(err)
}

ReadLine

簡單(單任務)下載
newDL, err := curl.New("http://npm.taobao.org/mirrors/node/v0.10.26/node.exe")
fmt.Printf("curl.New return ld  is %v\n", newDL)
fmt.Printf("curl.New return err is %v\n", err)

Simple-download

多任務下載
// mode 1
ts := curl.Task{}
ts1 := ts.New("http://xxx.xxx.xxx/node/latest/node.exe", "node.exe")
ts2 := ts.New("http://xxx.xxx.xxx/node/v4.0.0/win-x64/node.exe", "node40.exe")
ts3 := ts.New("http://xxx.xxx.xxx/node/v4.1.0/win-x64/node.exe", "node41.exe")
ts4 := ts.New("http://xxx.xxx.xxx/node/v4.2.0/win-x64/node.exe", "node42.exe")
ts5 := ts.New("http://xxx.xxx.xxx/node/v4.3.0/win-x64/node41.exe", "node43.exe")
newDL, err := curl.New(ts1, ts2, ts3, ts4, ts5, ts6)

fmt.Printf("curl.New return ld  is %v\n", newDL)
fmt.Printf("curl.New return err is %v\n", err)

// mode 2
dl := curl.Download {
    ts.New("http://7x2xql.com1.z0.glb.clouddn.com/visualhunt.json"),
    ts.New("http://7x2xql.com1.z0.glb.clouddn.com/holiday/02073.jpg"),
    ts.New("http://7x2xql.com1.z0.glb.clouddn.com/holiday/0207.jpg"),
}
dl.AddTask(ts.New("http://npm.taobao.org/mirrors/node/latest/node.exe", "nodeeeeeeeeeeeeeeeeeeeeeeee.exe", os.TempDir()))
dl.AddTask(ts.New("http://npm.taobao.org/mirrors/node/v5.7.0/win-x64/node.exe", "node4.exe", os.TempDir()))
dl.AddTask(ts.New("https://www.google.com/intl/zh-CN/chrome/browser/?standalone=1&extra=devchannel&platform=win64", "ChromeSetup.zip", os.TempDir()))
newDL, err := curl.New(dl)

fmt.Printf("curl.New return ld  is %v\n", newDL)
fmt.Printf("curl.New return err is %v\n", err)

Multi-download

自定義下載進度條樣式

custom progress schematic

// npm like
curl.Options.Header = false
curl.Options.Footer = false
curl.Options.LeftEnd = ""
curl.Options.RightEnd = ""
curl.Options.Fill = "█"
curl.Options.Arrow = ""
curl.Options.Empty = "░"

newDL, err := New("http://npm.taobao.org/mirrors/node/v0.10.26/node.exe")

node.exe: 100% ███████████████████████████████████████░░░░░░░░ 4s

custom download progressbar

相關鏈接

更新日誌

  • 2016-03-10, Version 0.0.4 support:

    • Add multi download.
    • Add custom progress.
    • Rework curl.New function.
    • Adapter Go 1.6.
  • 2016-03-05, Version 0.0.3 support:

    • Add beautiful dowload print.
  • 2014-07-10, Version 0.0.2 support:

    • Adapter Go 1.3.
  • 2014-05-28, Version 0.0.1 support:

    • New
    • Get
    • Readline

授權

license-badge