Skip to content
This repository was archived by the owner on May 29, 2018. It is now read-only.

Commit ec920e5

Browse files
committed
Expand README with usage examples
1 parent fbd02ff commit ec920e5

File tree

1 file changed

+116
-0
lines changed

1 file changed

+116
-0
lines changed

README.md

Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ httpfstream
44
httpfstream provides HTTP handlers for simultaneous streaming uploads and
55
downloads of files, as well as persistence and a standalone server.
66

7+
It allows a writer to `APPEND` data to a resource via a WebSocket and multiple
8+
readers to `FOLLOW` updates to the resource using WebSockets.
9+
710
* [Documentation on Sourcegraph](https://sourcegraph.com/github.com/sourcegraph/httpfstream)
811

912
[![Build Status](https://travis-ci.org/sourcegraph/httpfstream.png?branch=master)](https://travis-ci.org/sourcegraph/httpfstream)
@@ -12,3 +15,116 @@ downloads of files, as well as persistence and a standalone server.
1215
[![top func](https://sourcegraph.com/api/repos/github.com/sourcegraph/httpfstream/badges/top-func.png)](https://sourcegraph.com/github.com/sourcegraph/httpfstream)
1316
[![library users](https://sourcegraph.com/api/repos/github.com/sourcegraph/httpfstream/badges/library-users.png)](https://sourcegraph.com/github.com/sourcegraph/httpfstream)
1417
[![status](https://sourcegraph.com/api/repos/github.com/sourcegraph/httpfstream/badges/status.png)](https://sourcegraph.com/github.com/sourcegraph/httpfstream)
18+
19+
20+
Installation
21+
------------
22+
23+
```bash
24+
go get github.com/sourcegraph/httpfstream
25+
```
26+
27+
28+
Usage
29+
-----
30+
31+
httpfstream supports 2 modes of usage: as a standalone server or as a Go
32+
library.
33+
34+
### As a standalone server
35+
36+
The command `httpfstream-server` launches a server that allows clients to APPEND
37+
and FOLLOW arbitrary file paths. Run with `-h` for more information.
38+
39+
For example, run the server with:
40+
41+
```bash
42+
$ httpfstream-server -root=/tmp/httpfstream -http=:8080
43+
```
44+
45+
Then launch a follower on `/foo.txt`:
46+
47+
```bash
48+
$ httpfstream-follow -v http://localhost:8080/foo.txt
49+
# keep this terminal window open
50+
```
51+
52+
And start appending to `/foo.txt` in a separate terminal:
53+
54+
```bash
55+
$ httpfstream-append -v http://localhost:8080/foo.txt
56+
# start typing:
57+
foo
58+
bar
59+
baz
60+
# now exit: ctrl-C
61+
```
62+
63+
Notice that the `httpfstream-follow` window echoes what you type into the
64+
appender window. Once you close the appender, the follower quits as well.
65+
66+
If there are no appenders at an existing resource, the server returns the full
67+
data in an HTTP 200 (bypassing WebSockets). If the resource has never been
68+
written to, the server responds with HTTP 404.
69+
70+
71+
### As a Go library
72+
73+
#### Server
74+
75+
The function [`httpfstream.New(root
76+
string)`](https://sourcegraph.com/github.com/sourcegraph/httpfstream/symbols/go/github.com/sourcegraph/httpfstream/New)
77+
takes the root file storage path as a parameter and returns an
78+
[`http.Handler`](https://sourcegraph.com/code.google.com/p/go/symbols/go/code.google.com/p/go/src/pkg/net/http/Handler:type)
79+
that lets clients `APPEND` and `FOLLOW` to paths it handles.
80+
81+
The file `cmd/httpfstream-server/server.go` contains a full example, summarized here:
82+
83+
```go
84+
package main
85+
86+
import (
87+
"github.com/sourcegraph/httpfstream"
88+
"log"
89+
"net/http"
90+
"os"
91+
)
92+
93+
func main() {
94+
h := httpfstream.New("/tmp/httpfstream")
95+
h.Log = log.New(os.Stderr, "", 0)
96+
http.Handle("/", h)
97+
98+
err := http.ListenAndServe(":8080", nil)
99+
if err != nil {
100+
log.Fatalf("ListenAndServe: %s", err)
101+
}
102+
}
103+
```
104+
105+
#### Appender
106+
107+
Clients can append data to a resource using either [`httpfstream.Append(u *url.URL,
108+
r io.Reader) error`](https://sourcegraph.com/github.com/sourcegraph/httpfstream/symbols/go/github.com/sourcegraph/httpfstream/Append)
109+
(if they already have an `io.Reader`) or [`httpfstream.OpenAppend(u *url.URL)
110+
(io.WriteCloser,
111+
error)`](https://sourcegraph.com/github.com/sourcegraph/httpfstream/symbols/go/github.com/sourcegraph/httpfstream/OpenAppend).
112+
113+
Click on the function names (linked above) to see full docs and usage examples
114+
on Sourcegraph.
115+
116+
117+
#### Follower
118+
119+
Clients can follow a resource's data using [`httpfstream.Follow(u *url.URL)
120+
(io.ReadCloser, error)`](https://sourcegraph.com/github.com/sourcegraph/httpfstream/symbols/go/github.com/sourcegraph/httpfstream/Follow).
121+
122+
Click on the function names (linked above) to see full docs and usage examples
123+
on Sourcegraph.
124+
125+
126+
Contributing
127+
------------
128+
129+
Patches and bug reports welcomed! Report issues and submit pull requests using
130+
GitHub.

0 commit comments

Comments
 (0)