/
test-blob-stream.js
63 lines (53 loc) · 1.83 KB
/
test-blob-stream.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
/*
Copyright by Denys Khanzhiyev
See license text in LICENSE file
*/
// Load configuration
var cfg = require("../config").cfg;
// Require modules
var
fb_binding = require("../../firebird");
var
testCase = require("../../tools/nodeunit").testCase;
var
fs = require('fs');
var
sys = require("sys");
var util = {
createTestTable: function(datatype){
this.conn.querySync('create table BLOB_TEST_TABLE ( test_field '+datatype+')');
},
quote:function(val){ return "'"+val+"'";}
};
module.exports = testCase({
setUp: function(callback){
this.conn = new fb_binding.createConnection();
this.conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
callback();
},
tearDown: function(callback){
this.conn.disconnect();
this.conn = null;
var conn = new fb_binding.createConnection();
conn.connectSync(cfg.db, cfg.user, cfg.password, cfg.role);
conn.querySync('drop table BLOB_TEST_TABLE');
conn.disconnect();
callback();
},
fileInsert: function(test){
test.expect(1);
util.createTestTable.call(this,'BLOB SUB_TYPE 0');
var stmt = this.conn.prepareSync('insert into BLOB_TEST_TABLE ( test_field ) values (?)');
var strm = new fb_binding.Stream(this.conn.newBlobSync());
test.ok(strm,'There is stream');
var fstrm = fs.createReadStream('tests/testdata/image.gif');
fstrm.resume();
fstrm.pipe(strm);
var self= this;
strm.on("close",function(){
stmt.execSync(strm._blob);
self.conn.commitSync();
test.done();
});
}
});