-
Notifications
You must be signed in to change notification settings - Fork 2
/
gridfs.js
69 lines (69 loc) · 2.29 KB
/
gridfs.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
(function() {
var Db, GridFS, GridStore, Server, configArgs, db, server_config;
configArgs = require('./config.js').config;
GridStore = require('mongodb').GridStore;
Db = require('mongodb').Db;
Server = require('mongodb').Server;
server_config = new Server(configArgs.mongo.host, configArgs.mongo.port, {
auto_reconnect: true
});
db = new Db(configArgs.mongo.dbname, server_config);
db.open(function(err, db) {
return console.log("%s grid fs is open", root);
});
GridFS = (function() {
function GridFS(options) {
this.options = options;
}
GridFS.prototype.writeFile = function(filename, path, cb) {
var gridStore, _options;
_options = this.options;
gridStore = new GridStore(db, filename, "w", _options);
return gridStore.open(function(err, gridStore) {
return gridStore.writeFile(path, function(err, result) {
return gridStore.close(function(err, result) {
return cb(err, result);
});
});
});
};
GridFS.prototype.write = function(filename, content, cb) {
var gridStore, _options;
_options = this.options;
gridStore = new GridStore(db, filename, "w", _options);
return gridStore.open(function(err, gridStore) {
return gridStore.write(content, function(err, gridStore) {
return gridStore.close(function(err, result) {
return cb(err);
});
});
});
};
GridFS.prototype.unlink = function(filename, cb) {
var _options;
_options = this.options;
return GridStore.unlink(db, filename, _options, function(err, content) {
return cb(err);
});
};
GridFS.prototype.stream = function(filename, cb) {
var gridStore, _options;
_options = this.options;
gridStore = new GridStore(db, filename, "r", _options);
return gridStore.open(function(err, gridStore) {
var fileStream;
fileStream = gridStore.stream(true);
return cb(err, fileStream);
});
};
GridFS.prototype.exist = function(filename, cb) {
var _options;
_options = this.options;
return GridStore.exist(db, filename, _options.root, function(err, exist) {
return cb(err, exist);
});
};
return GridFS;
})();
exports.GridFS = GridFS;
}).call(this);