Categorygithub.com/ananthb/chonker
modulepackage
1.3.4
Repository: https://github.com/ananthb/chonker.git
Documentation: pkg.go.dev

# README

Chonker

Chonker

Go Reference

Download large files as parallel chunks using HTTP Range Requests in Go.

CI

Chonker works on Go 1.19, oldstable, and stable releases.

What does Chonker do?

Chonker speeds up downloads from cloud services like Amazon S3 & CloudFront. It does this in two ways.

  1. Download small pieces of a file (a.k.a a chunk) using HTTP Range requests.
  2. Download chunks in parallel.

Why?

Chonker allows CDN services to cache and serve files even if the entire file is bigger than the individual object cache limit.

It also overcomes the per-connection limit that blob storage services often have by opening connections in parallel.

The Go standard library HTTP Client downloads files as buffered streams of bytes. The Client fetches bytes into a request buffer as fast as it can, and you read bytes from the buffer as fast as you can.

Why is this a problem?

This works great when one beefy connection to an origin server can use the entire available network bandwidth between you and it. Blob file services like Amazon S3 and caching CDNs like Amazon CloudFront impose per-connection limits, but support an almost unlimited number of connections from each client.

If you are downloading a large file from S3, its almost always better to download the file in chunks, using parallel connections.

See the S3 Developer Guide and the CloudFront Developer Guide for more information on cache sizes and parallel GETs.

Use Chonker

Use chonker.Do to fetch a response for a request, or create a "chonky" http.Transport that fetches requests using HTTP Range sub-requests.

Chonker integrates well with Go download libraries. Grab and other download managers can use a http.Client with a "chonky" http.Transport. In turn, Chonker functions accept HTTP clients that could provide automatic retries or detailed logs. See Heimdall or go-retryablehttp for more.

Chonk

Chonk is a Go program that uses the chonker library to download a URL into a local file. Run chonk -h for usage details.

go build -o chonk ./cmd/chonk

./chonk https://example.com

test.sh

test.sh is a BASH shell script that exercises the chonk program with a list of files of varying sizes. Run test.sh -h for usage details.

License

The Chonker cat illustration is from Freepik

Chonker is available under the terms of the MIT license.

See LICENSE for the full license text.

# Packages

No description provided by the author

# Functions

Chunks divides the range [offset, size) into chunks of size chunkSize.
Do sends an HTTP request and returns an HTTP response, following policy (such as redirects, cookies, auth) as configured on the client.
New returns a chonker client with default settings.
NewClient returns a new http.Client that fetches requests in chunks.
NewRequest returns a new Request.
NewRequestWithContext returns a new Request.
NewRoundTripper returns a new http.RoundTripper that fetches requests in chunks.
ParseContentRange parses a Content-Range header string as per [RFC 7233].
ParseRange parses a Range header string as per [RFC 7233].

# Variables

No description provided by the author
ErrInvalidRange is returned by ParseRange on invalid input.
No description provided by the author
ErrRangeNoOverlap is returned by ParseRange if first-byte-pos of all of the byte-range-spec values is greater than the content size.
No description provided by the author
ErrUnsatisfiedRange is returned by ParseContentRange if the range is not satisfied.
StatsForNerds exposes Prometheus metrics for chonker requests.

# Structs

Chunk represents a byte range.
Request is a ranged http.Request.