Documentation
¶
Overview ¶
httpseek is a go package that implements io.Seeker and io.ReaderAt interface on HTTP Response bodies. This allows the client to read parts of a file without downloading it entirely.
To achieve this the HTTP Range request is used. If the HTTP server does not support this, the request will fail.
To prevent lots of tiny http request a buffer is implemented.
Example ¶
package main
import (
"fmt"
"io"
"github.com/hnz/httpseek"
)
func main() {
client := new(httpseek.Client)
client.Blocksize = 64 * 1024
resp, err := client.Get("http://textfiles.com/100/phrack.01.phk")
if err != nil {
panic(err)
}
buf := make([]byte, 33)
x, err := resp.Body.Seek(555, io.SeekStart)
y, err := resp.Body.Read(buf)
if err != nil {
panic(err)
}
fmt.Printf("Read %d bytes starting from position %d. Output: %s", y, x, buf)
}
Output: Read 33 bytes starting from position 555. Output: Welcome to the Phrack Inc. Philes
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var Logger *log.Logger
Logger logs debug messages if set
Functions ¶
This section is empty.
Types ¶
type Client ¶
Client is an implementation of http.Client that allows for the response body to be seeked
Example ¶
package main
import (
"archive/zip"
"fmt"
"github.com/hnz/httpseek"
)
func main() {
client := new(httpseek.Client)
client.Blocksize = 64 * 1024
resp, err := client.Get("https://climate.onebuilding.org/WMO_Region_6_Europe/LUX_Luxembourg/LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.zip")
if err != nil {
panic(err)
}
archive, err := zip.NewReader(&resp.Body, resp.ContentLength)
if err != nil {
panic(err)
}
for _, f := range archive.File {
fmt.Println("Found file", f.Name)
}
}
Output: Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.clm Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.ddy Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.epw Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.pvsyst Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.rain Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.stat Found file LUX_LU_Luxembourg.AP.065900_TMYx.2004-2018.wea
type RangeNotSupported ¶
type RangeNotSupported struct {
Url string
}
RangeNotSupported is returned when the remote http server does not support the http Range header
func (*RangeNotSupported) Error ¶
func (e *RangeNotSupported) Error() string
type ReaderAtBuffer ¶
type Response ¶
type Response struct {
*http.Response
Body ResponseBody
}
type ResponseBody ¶
type ResponseBody struct {
ReaderAtBuffer
Body io.ReadCloser
// contains filtered or unexported fields
}
ResponseBody implents the io.ReaderAt and io.Seeker interfaces
Click to show internal directories.
Click to hide internal directories.