Automatically migrated from Gitolite
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.4 KiB

7 years ago
  1. streamLength = require "./"
  2. fs = require "fs"
  3. request = require "request"
  4. http = require "http"
  5. Promise = require "bluebird"
  6. Promise.try ->
  7. console.log "Length of fs:README.md..."
  8. streamLength fs.createReadStream("README.md")
  9. .then (length) ->
  10. console.log "Length", length
  11. .catch (err) ->
  12. console.log "No-Length", err
  13. .then ->
  14. console.log "Length of Buffer..."
  15. streamLength new Buffer("testing buffer content length retrieval...")
  16. .then (length) ->
  17. console.log "Length", length
  18. .catch (err) ->
  19. console.log "No-Length", err
  20. .then ->
  21. console.log "Length of http:Google"
  22. new Promise (resolve, reject) ->
  23. http.get "http://www.google.com/images/srpr/logo11w.png", (res) ->
  24. resolve res
  25. .on "error", (err) ->
  26. reject err
  27. .then (res) ->
  28. res.resume() # Drain the stream
  29. streamLength res
  30. .then (length) ->
  31. console.log "Length", length
  32. .catch (err) ->
  33. console.log "No-Length", err
  34. .then ->
  35. console.log "Length of request:Google..."
  36. streamLength request "http://www.google.com/images/srpr/logo11w.png", (err, res, body) ->
  37. # Ignore...
  38. .then (length) ->
  39. console.log "Length", length
  40. .catch (err) ->
  41. console.log "No-Length", err
  42. .then ->
  43. console.log "Length of request:Google:fail..."
  44. streamLength request "http://www.google.com/", (err, res, body) ->
  45. # Ignore...
  46. .then (length) ->
  47. console.log "Length", length
  48. .catch (err) ->
  49. console.log "No-Length", err