10 // WebFile is an implementation of File which reads it
11 // from a Web URL (http). A GET request will be performed
12 // against the source when calling Read().
19 // NewWebFile creates a WebFile with the given URL, which
20 // will be used to perform the GET request on Read().
21 func NewWebFile(url *url.URL) *WebFile {
27 // Read reads the File from it's web location. On the first
28 // call to Read, a GET request will be performed against the
29 // WebFile's URL, using Go's default HTTP client. Any further
30 // reads will keep reading from the HTTP Request body.
31 func (wf *WebFile) Read(b []byte) (int, error) {
33 resp, err := http.Get(wf.url.String())
38 wf.contentLength = resp.ContentLength
40 return wf.body.Read(b)
43 // Close closes the WebFile (or the request body).
44 func (wf *WebFile) Close() error {
48 return wf.body.Close()
52 func (wf *WebFile) Seek(offset int64, whence int) (int64, error) {
53 return 0, ErrNotSupported
56 func (wf *WebFile) Size() (int64, error) {
57 if wf.contentLength < 0 {
58 return -1, errors.New("Content-Length hearer was not set")
61 return wf.contentLength, nil
64 var _ File = &WebFile{}