test.coffee
1.35 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
streamLength = require "./"
fs = require "fs"
request = require "request"
http = require "http"
Promise = require "bluebird"
Promise.try ->
console.log "Length of fs:README.md..."
streamLength fs.createReadStream("README.md")
.then (length) ->
console.log "Length", length
.catch (err) ->
console.log "No-Length", err
.then ->
console.log "Length of Buffer..."
streamLength new Buffer("testing buffer content length retrieval...")
.then (length) ->
console.log "Length", length
.catch (err) ->
console.log "No-Length", err
.then ->
console.log "Length of http:Google"
new Promise (resolve, reject) ->
http.get "http://www.google.com/images/srpr/logo11w.png", (res) ->
resolve res
.on "error", (err) ->
reject err
.then (res) ->
res.resume() # Drain the stream
streamLength res
.then (length) ->
console.log "Length", length
.catch (err) ->
console.log "No-Length", err
.then ->
console.log "Length of request:Google..."
streamLength request "http://www.google.com/images/srpr/logo11w.png", (err, res, body) ->
# Ignore...
.then (length) ->
console.log "Length", length
.catch (err) ->
console.log "No-Length", err
.then ->
console.log "Length of request:Google:fail..."
streamLength request "http://www.google.com/", (err, res, body) ->
# Ignore...
.then (length) ->
console.log "Length", length
.catch (err) ->
console.log "No-Length", err