Skip to content

Kenshin/curl

Repository files navigation

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