Gofetch
Go library for downloading content from internet, in parallel.
Install / Use
/learn @c4milo/GofetchREADME
Gofetch
Go library to download files from the internerds using Go 1.7 or greater.
Features
- Resumes downloads if interrupted.
- Allows parallel downloading of a single file by requesting multiple data chunks at once over HTTP.
- Reports download progress through a Go channel if indicated to do so.
- Supports file integrity verification if a checksum is provided.
- Supports ETags, skipping downloading a file if it hasn't changed on the server.
- Can be combined with https://github.com/cenkalti/backoff to support retrying with exponential back-off
Gotchas
When downloading file chunks concurrently, you may encounter some issues:
- Servers may limit the number of concurrent connections you have open against them
- Servers may accept the connections but will not send anything, in this case the default HTTP client will timeout for you. If you provide your own client, make sure it has proper timeouts or your connection will block for several seconds, depending on your operating system network timeouts.
Example
package main
import (
"fmt"
"io"
"os"
"github.com/c4milo/gofetch"
)
func main() {
gf := gofetch.New(
gofetch.WithDestDir(os.TempDir()),
gofetch.WithConcurrency(10),
gofetch.WithETag(),
)
progressCh := make(chan gofetch.ProgressReport)
var myFile *os.File
go func() {
var err error
myFile, err = gf.Fetch(
"http://releases.ubuntu.com/15.10/ubuntu-15.10-server-amd64.iso",
progressCh)
if err != nil {
panic(err)
}
}()
// pogressCh is close by gofetch once a download finishes
var totalWritten int64
for p := range progressCh {
// p.WrittenBytes does not accumulate, it represents the chunk size written
// in the current operation.
totalWritten += p.WrittenBytes
fmt.Printf("%d of %d\n", totalWritten, p.Total)
}
destFile, err := os.Create("/tmp/ubuntu-15.10-server-amd64.iso")
if err != nil {
panic(err)
}
defer func() {
if err := destFile.Close(); err != nil {
panic(err)
}
}()
if _, err := io.Copy(destFile, myFile); err != nil {
panic(err)
}
}
Related Skills
xurl
347.6kA CLI tool for making authenticated requests to the X (Twitter) API. Use this skill when you need to post tweets, reply, quote, search, read posts, manage followers, send DMs, upload media, or interact with any X API v2 endpoint.
qqbot-channel
347.6kQQ 频道管理技能。查询频道列表、子频道、成员、发帖、公告、日程等操作。使用 qqbot_channel_api 工具代理 QQ 开放平台 HTTP 接口,自动处理 Token 鉴权。当用户需要查看频道、管理子频道、查询成员、发布帖子/公告/日程时使用。
docs-writer
100.2k`docs-writer` skill instructions As an expert technical writer and editor for the Gemini CLI project, you produce accurate, clear, and consistent documentation. When asked to write, edit, or revie
model-usage
347.6kUse CodexBar CLI local cost usage to summarize per-model usage for Codex or Claude, including the current (most recent) model or a full model breakdown. Trigger when asked for model-level usage/cost data from codexbar, or when you need a scriptable per-model summary from codexbar cost JSON.
