-
Notifications
You must be signed in to change notification settings - Fork 30
/
read-write.js
107 lines (90 loc) · 3.19 KB
/
read-write.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
var from = require('from2-array')
var concat = require('concat-stream')
module.exports.blobWriteStream = function(test, common) {
test('piping a blob into a blob write stream', function(t) {
common.setup(test, function(err, store) {
t.notOk(err, 'no setup err')
var ws = store.createWriteStream({name: 'test.js'}, function(err, obj) {
t.error(err)
t.ok(obj.key, 'blob has key')
common.teardown(test, store, obj, function(err) {
t.error(err)
t.end()
})
})
from([new Buffer('foo'), new Buffer('bar')]).pipe(ws)
})
})
}
module.exports.blobReadStream = function(test, common) {
test('reading a blob as a stream', function(t) {
common.setup(test, function(err, store) {
t.notOk(err, 'no setup err')
var ws = store.createWriteStream({name: 'test.js'}, function(err, blob) {
t.notOk(err, 'no blob write err')
t.ok(blob.key, 'blob has key')
var rs = store.createReadStream(blob)
rs.on('error', function(e) {
t.false(e, 'no read stream err')
t.end()
})
rs.pipe(concat(function(file) {
t.equal(file.length, 6, 'blob length is correct')
common.teardown(test, store, blob, function(err) {
t.error(err)
t.end()
})
}))
})
from([new Buffer('foo'), new Buffer('bar')]).pipe(ws)
})
})
}
module.exports.blobReadError = function(test, common) {
test('reading a blob that does not exist', function(t) {
common.setup(test, function(err, store) {
t.notOk(err, 'no setup err')
var rs = store.createReadStream({name: 'test.js', key: '8843d7f92416211de9ebb963ff4ce28125932878'})
rs.on('error', function(e) {
t.ok(e, 'got a read stream err')
// t.ok(e.notFound, 'error reports not found')
common.teardown(test, store, undefined, function(err) {
t.error(err)
t.end()
})
})
})
})
}
module.exports.blobExists = function(test, common) {
test('check if a blob exists', function(t) {
common.setup(test, function(err, store) {
t.notOk(err, 'no setup err')
var blobMeta = {name: 'test.js', key: '8843d7f92416211de9ebb963ff4ce28125932878'}
store.exists(blobMeta, function(err, exists) {
t.error(err)
t.notOk(exists, 'does not exist')
var ws = store.createWriteStream({name: 'test.js'}, function(err, obj) {
t.notOk(err, 'no blob write err')
t.ok(obj.key, 'blob has key')
// on this .exists call use the metadata from the writeStream
store.exists(obj, function(err, exists) {
t.error(err)
t.ok(exists, 'exists')
common.teardown(test, store, obj, function(err) {
t.error(err)
t.end()
})
})
})
from([new Buffer('foo'), new Buffer('bar')]).pipe(ws)
})
})
})
}
module.exports.all = function (test, common) {
module.exports.blobWriteStream(test, common)
module.exports.blobReadStream(test, common)
module.exports.blobReadError(test, common)
module.exports.blobExists(test, common)
}