buffered-xhr-stream
Advanced tools
Comparing version 0.1.2 to 0.1.3
20
index.js
var stream = require('stream') | ||
, util = require('util') | ||
function Stream (xhr, options) { | ||
options = options || {} | ||
function Stream (options) { | ||
if (!options) { | ||
throw new Error('options are required') | ||
} | ||
if (!options.xhr && !options.url) { | ||
throw new Error('options.xhr or options.url is required') | ||
} | ||
stream.Stream.call(this) | ||
this.xhr = xhr | ||
this.offset = 0 | ||
@@ -16,4 +20,10 @@ this.paused = false | ||
this.capable = true | ||
xhr.onreadystatechange = this.handle.bind(this) | ||
xhr.send(null) | ||
this.xhr = options.xhr | ||
if (options.url) { | ||
this.xhr = new XMLHttpRequest | ||
this.xhr.open('GET', options.url, true) | ||
} | ||
this.xhr.onreadystatechange = this.handle.bind(this) | ||
this.xhr.send(null) | ||
} | ||
@@ -20,0 +30,0 @@ |
{ | ||
"name": "buffered-xhr-stream", | ||
"version": "0.1.2", | ||
"version": "0.1.3", | ||
"description": "A pausable/resumable xhr stream", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
3548
72
36