binary.js 864 B

1234567891011121314151617181920212223242526272829303132
  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. // Binary data gets corrupted in IE8 or below
  10. var skipVerification = (browserName === 'IE' && browserVersion <= 8)
  11. var reference = fs.readFileSync(__dirname + '/../server/static/browserify.png')
  12. test('binary download', function (t) {
  13. http.get('/browserify.png', function (res) {
  14. var buffers = []
  15. res.on('end', function () {
  16. if (skipVerification)
  17. t.skip('binary data not preserved on IE <= 8')
  18. else
  19. t.ok(reference.equals(Buffer.concat(buffers)), 'contents match')
  20. t.end()
  21. })
  22. res.on('data', function (data) {
  23. buffers.push(data)
  24. })
  25. })
  26. })