a zip code crypto-currency system good for red ONLY

text-streaming.js 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. var Buffer = require('buffer').Buffer
  2. var fs = require('fs')
  3. var test = require('tape')
  4. var UAParser = require('ua-parser-js')
  5. var http = require('../..')
  6. var browser = (new UAParser()).setUA(navigator.userAgent).getBrowser()
  7. var browserName = browser.name
  8. var browserVersion = browser.major
  9. // Streaming doesn't work in IE9 or below
  10. var skipStreamingCheck = (browserName === 'IE' && browserVersion <= 9)
  11. var COPIES = 1000
  12. var MIN_PIECES = 5
  13. var referenceOnce = fs.readFileSync(__dirname + '/../server/static/basic.txt')
  14. var reference = new Buffer(referenceOnce.length * COPIES)
  15. for(var i = 0; i < COPIES; i++) {
  16. referenceOnce.copy(reference, referenceOnce.length * i)
  17. }
  18. test('text streaming', function (t) {
  19. http.get({
  20. path: '/basic.txt?copies=' + COPIES,
  21. mode: 'prefer-streaming'
  22. }, function (res) {
  23. var buffers = []
  24. res.on('end', function () {
  25. if (skipStreamingCheck)
  26. t.skip('streaming not available on IE <= 8')
  27. else
  28. t.ok(buffers.length >= MIN_PIECES, 'received in multiple parts')
  29. t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
  30. t.end()
  31. })
  32. res.on('data', function (data) {
  33. buffers.push(data)
  34. })
  35. })
  36. })