Newer
Older
alert / js / node_modules / stream-http / test / browser / lib / webworker-worker.js
@Réz István Réz István on 18 Nov 2021 395 bytes first commit
var Buffer = require('buffer').Buffer

var http = require('../../..')

module.exports = function (self) {
	self.addEventListener('message', function (ev) {
		var url = ev.data
		http.get(url, function (res) {
			var buffers = []

			res.on('end', function () {
				self.postMessage(Buffer.concat(buffers).buffer)
			})

			res.on('data', function (data) {
				buffers.push(data)
			})
		})
	})
}