webworker-worker.js 395 B

1234567891011121314151617181920
  1. var Buffer = require('buffer').Buffer
  2. var http = require('../../..')
  3. module.exports = function (self) {
  4. self.addEventListener('message', function (ev) {
  5. var url = ev.data
  6. http.get(url, function (res) {
  7. var buffers = []
  8. res.on('end', function () {
  9. self.postMessage(Buffer.concat(buffers).buffer)
  10. })
  11. res.on('data', function (data) {
  12. buffers.push(data)
  13. })
  14. })
  15. })
  16. }