Documentation
¶
Overview ¶
Package httpreaderat allows opening a URL as a io.ReaderAt.
Example ¶
package main
import (
"embed"
"fmt"
"net/http"
"net/http/httptest"
"vimagination.zapto.org/httpreaderat"
)
//go:embed example_test.go
var f embed.FS
func main() {
srv := httptest.NewServer(http.FileServerFS(f))
r, err := httpreaderat.NewRequest(srv.URL + "/example_test.go")
if err != nil {
fmt.Println(err)
return
}
buf := make([]byte, 17)
n, err := r.ReadAt(buf, 8)
fmt.Printf("Bytes: %d\nErr: %v\nRead: %s", n, err, buf)
}
Output: Bytes: 17 Err: <nil> Read: httpreaderat_test
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrNoRange = errors.New("no range header")
Errors.
Functions ¶
This section is empty.
Types ¶
type Client ¶ added in v1.0.2
Client is an interface representing the method required when performing HTTP requests, usually implemented by *http.Client.
type Option ¶
type Option func(*Request)
Option is an option that can be parsed to NewRequest.
func CacheCount ¶
CacheCount changes the number of cached blocks from 256.
func HTTPClient ¶ added in v1.0.2
HTTPClient allows the setting of a custom HTTP client, instead of http.DefaultClient allowing the setting of custom HTTP options.
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
Request represents an io.ReaderAt for an HTTP URL.
func NewRequest ¶
NewRequest creates a new Request object, for the given URL, that implements io.ReaderAt.
Options can be passed in to modify how the maximum length is determined, and the characteristics of the block caching.
By default, up to 256 4KB blocks will be cached.