Skip to content

Commit 1042166

Browse files
committed
Expose LOB functionality as a stream
1 parent c5163d9 commit 1042166

File tree

1 file changed

+92
-10
lines changed

1 file changed

+92
-10
lines changed

lib/oracledb.js

Lines changed: 92 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,102 @@ try {
2727
} else {
2828
throw err;
2929
}
30-
}
30+
}
31+
32+
var Duplex = require('stream').Duplex;
33+
var util = require('util');
34+
35+
util.inherits(Lob, Duplex);
36+
37+
function Lob(iLob, opt)
38+
{
39+
Duplex.call(this, opt);
40+
this.iLob = iLob;
41+
this.once('finish', this.close);
42+
Object.defineProperties(
43+
this,
44+
{
45+
"chunkSize": {value: iLob.chunkSize,
46+
writable: false },
47+
48+
"length": {get: function() {return iLob.length}},
49+
50+
"pieceSize": {get: function() {return iLob.pieceSize;},
51+
set: function(newPieceSize) {iLob.pieceSize = newPieceSize;}},
52+
});
53+
}
54+
55+
Lob.prototype._read = function()
56+
{
57+
var self = this;
58+
59+
self.iLob.read(
60+
function(err, str)
61+
{
62+
if (err) {
63+
self.close();
64+
self.emit('error', err);
65+
return;
66+
}
67+
if (!str) {
68+
self.close();
69+
}
70+
self.push(str);
71+
});
72+
}
73+
74+
Lob.prototype._write = function(data, encoding, cb)
75+
{
76+
var self = this;
77+
78+
self.iLob.write(
79+
data,
80+
function(err)
81+
{
82+
if (err) {
83+
self.close();
84+
return cb(err);
85+
}
86+
cb();
87+
});
88+
}
89+
90+
Lob.prototype.close = function(cb)
91+
{
92+
var self = this;
93+
94+
if (cb) {
95+
this.once('close', cb);
96+
}
97+
98+
if (self.iLob != null) {
99+
self.iLob.release();
100+
self.iLob = null;
101+
}
102+
self.emit('close');
103+
}
104+
105+
oracledb.Oracledb.prototype.newLob = function(iLob)
106+
{
107+
return new Lob(iLob, null);
108+
}
31109

32110
var oracledb_ins = new oracledb.Oracledb();
33111

34-
oracledb_ins.STRING = 2001;
35-
oracledb_ins.NUMBER = 2002;
36-
oracledb_ins.DATE = 2003;
37-
oracledb_ins.CURSOR = 2004;
112+
oracledb_ins.DEFAULT = 0;
113+
oracledb_ins.STRING = 2001;
114+
oracledb_ins.NUMBER = 2002;
115+
oracledb_ins.DATE = 2003;
116+
oracledb_ins.CURSOR = 2004;
117+
oracledb_ins.BUFFER = 2005;
118+
oracledb_ins.CLOB = 2006;
119+
oracledb_ins.BLOB = 2007;
38120

39-
oracledb_ins.BIND_IN = 3001;
40-
oracledb_ins.BIND_INOUT = 3002;
41-
oracledb_ins.BIND_OUT = 3003;
121+
oracledb_ins.BIND_IN = 3001;
122+
oracledb_ins.BIND_INOUT = 3002;
123+
oracledb_ins.BIND_OUT = 3003;
42124

43-
oracledb_ins.ARRAY = 4001;
44-
oracledb_ins.OBJECT = 4002;
125+
oracledb_ins.ARRAY = 4001;
126+
oracledb_ins.OBJECT = 4002;
45127

46128
module.exports = oracledb_ins;

0 commit comments

Comments
 (0)