-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
60 lines (54 loc) · 1.64 KB
/
index.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
var pseudoFS = null;
var util = require('util');
try {
pseudoFS = require(__dirname + '/build/Debug/pseudofs.node');
console.error(" ********** using pseudoFS debug module. ************* ");
} catch(e) {
try {
pseudoFS = require(__dirname + '/build/Release/pseudofs.node');
} catch(e) {
console.error(" ********** is pseudofs built???? Error: " + util.inspect(e));
}
}
// callback = function(error,Buffer,readlen) {}
var readPseudo = function(path, options, callback) {
var _cb;
if(callback) _cb = callback; else _cb = options;
var wrap = function(error,buf,readlen) {
var _buf = undefined;
if(!error) { // why?? because apparently the writers of node::Buffer thought
// console.dir(buf);
_buf = buf.slice(0,readlen); // that making the 'length_' property a private was a good idea - so easier to adjust size here.
}
else {
if(error.errno) { // match the standard node.js 'fs' error format.
error.code = pseudoFS.CONSTS[error.errno];
}
}
_cb(error,_buf);
}
if(callback) {
pseudoFS.readPseudo(path,options,wrap);
} else
pseudoFS.readPseudo(path,wrap);
}
var writePseudo = function(path, data, options, callback) {
var _cb;
if(callback) _cb = callback; else _cb = options;
var wrap = function(error) {
var _buf = undefined;
if(error && error.errno) { // match the standard node.js 'fs' error format.
error.code = pseudoFS.CONSTS[error.errno];
}
_cb(error,_buf);
}
if(callback) {
pseudoFS.writePseudo(path, data, options,wrap);
} else
pseudoFS.writePseudo(path, data, wrap);
}
module.exports = {
readPseudo: readPseudo,
writePseudo: writePseudo,
CONSTS: pseudoFS.CONSTS
}