forked from josephg/ShareJS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cat.coffee
34 lines (26 loc) · 855 Bytes
/
cat.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# A simple script to fetch a document from the server.
Connection = require('../src/client').Connection
getSocket = (hostname, port, docName) ->
c = new Connection(hostname, port)
c.get docName, (doc) ->
console.log (if typeof doc.snapshot == 'string'
doc.snapshot
else
JSON.stringify doc.snapshot)
c.disconnect()
http = require 'http'
getREST = (hostname, port, docName) ->
http.get {host: hostname, port: port, path: "/doc/#{docName}"}, (res) ->
message = []
res.on 'data', (data) -> message.push data
res.on 'end', ->
message = message.join ''
doc = JSON.parse message
if typeof doc.snapshot == 'string'
console.log doc.snapshot
else
console.log JSON.stringify(doc.snapshot)
if process.argv.length < 3
console.error "Usage: coffee cat.coffee DOCNAME"
else
getREST 'localhost', 8000, process.argv[2]