Coder Social home page Coder Social logo

httpreadat's Introduction

httpreadat: Go http range requests via an io.ReaderAt

httpreadat is a library for making http range requests exposed as a normal io.ReaderAt interface.

This is especially useful for interacting with large files stored in object stores like S3, where you only need to read certain parts of the file.

Example

	rr := New(url)
	rr.ReadAt(buf, offset)

Options

Request manipulation

You may need more control over the request beyond simply setting the url. For those cases you can optionally provide a custom http.RoundTripper. The RoundTripper has full access to the request to make any changes necessary before sending the request out.

Caching

Caching is often useful, especially when used with code that is not optimized for doing reads over the network. httpreadat provides an optional interface CacheHandler that you can implement for your own caching strategy.

The cache handler can make requests that are different than what ReadAt was called with. This allows for things like fetching a larger amount of data if the caller makes lots of small sequential reads.

There is an example CacheHandler in diskcache that fetches pages at a time and caches to a local os.File.

S3

The easiest way to use this with S3 is to make a presigned url for the S3 object and pass that url to New():

	req, _ := s3svc.GetObjectRequest(&s3.GetObjectInput{
		Bucket: aws.String(bucket),
		Key:    aws.String(path),
	})

	url, err := req.Presign(1 * time.Hour)
	if err != nil {
		return err
	}

	r := httpreadat.New(url)

httpreadat's People

Contributors

psanford avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

tpetr

httpreadat's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.