filereader-stream
Advanced tools
Comparing version 0.1.0 to 0.1.1
{ | ||
"name": "filereader-stream", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Read an HTML5 File object (from e.g. HTML5 drag and drops) as a stream.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
42
test.js
@@ -6,10 +6,40 @@ var test = require('tape'); | ||
test('should read file when one is dropped', function(t) { | ||
drop(document.body, function(files) { | ||
var first = files[0] | ||
frs(first).pipe(concat(function(contents) { | ||
t.true(contents.length > 0) | ||
t.end() | ||
drop(document.body, function(files) { | ||
var first = files[0], | ||
s = frs(first), | ||
cursor, paused | ||
test('should read file when one is dropped', function(t) { | ||
s.pipe(concat(function(contents) { | ||
t.true(contents.length > 0) | ||
t.end() | ||
})) | ||
}) | ||
s.on('progress', function(offset){ | ||
if (offset / first.size < 0.5 || paused) return | ||
test('should pause when over 30% of the file is read', function(t) { | ||
cursor = s.pause() | ||
t.true(cursor / first.size >= 0.5) | ||
t.end() | ||
}) | ||
test('should resume 2 seconds after pause', function(t) { | ||
setTimeout(function(){ | ||
s.resume() | ||
t.true(s.paused === false) | ||
t.end() | ||
}, 2000) | ||
}) | ||
paused = true | ||
}) | ||
s.on('end', function(offset){ | ||
test('should return correct offset upon end event', function(t) { | ||
t.true(first.size === offset) | ||
t.end() | ||
}) | ||
}) | ||
}) |
7326
117