Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
GridStore.exist(db, filename, fs, function(err, exists){
if(err){
self.emitter.emit('_op');
return callback(err, null);
}
if(exists === true){
new GridStore(db, filename, "r", options).open(function(err, gs){
if(offset != null){
gs.seek(offset, function(err, gridS){
if(err){
self.emitter.emit('_op');
return callback(err, null);
}
gridS.read(length, function(err, data){
callback(err, data);
self.emitter.emit('_op');
});
});
}else{
gs.read(length, function(err, data){
callback(err, data);
self.emitter.emit('_op');
});
.then(database => {
const gridStore = new GridStore(database, filename, 'r');
return gridStore.open();
})
.then(gridStore => {
this._run(function(db, done) {
GridStore(db, params.filename, 'w', { content_type: params.contentType || mime.lookup(params.filename) })
.open(function(err, gs) {
var stream = gs.stream();
stream.on('end', function(err) {
if (err) return done(err);
gs.close(done);
});
params.stream.pipe(stream);
});
}, cb);
}
var openDbFileWrite = function(filename, contentType, metadata, cb) {
var gridstore = new GridStore(
db,
filename,
'w',
{
root: rootCollection,
'content_type': contentType,
'chunk_size': 1024 * 1024,
metadata: metadata
}
);
gridstore.open(function(err, gs) {
cb(err, gs);
});
};
var openDbFileRead = function(filename, cb) {
var gridstore = new GridStore(
db,
filename,
'r',
{
root: rootCollection
}
);
gridstore.open(function(err, gs) {
cb(gs);
});
};
skin_db.open(function(err, p_db) {
if(err) return callback(err);
args = ([null, p_db]).concat(args);
var ctor = GridStore.bind.apply(GridStore, args);
var gridStore = new ctor();
gridStore.open(callback);
});
}
this.connectionProvider(function(err, db) {
if (err) {
return cb(err);
}
var gs = new mongodb.GridStore(db, blobName, "r", { "chunk_size": 1024 * 4 });
gs.open(function() {
try {
cb(null, gs.stream(true));
}
catch(e) {
cb(e);
}
});
});
};
skindb.open(function(err, p_db) {
args[0] = p_db;
GridStore[methodName].apply(GridStore, args);
});
}
dbopts = dbopts || { w: 1, journal: false, fsync: false };
this.db = new Db(dbname, new Server(host, port, {}), dbopts);
this.filename = filename;
this.readable = true
this.writable = false;
this.paused = false;
this.encoding = null;
this.options = options;
this.head = 0;
this.options['root'] = this.options['root'] || GridStore.DEFAULT_ROOT_COLLECTION;
this.options['chunk_size'] = this.options['chunk_size'] || Chunk.DEFAULT_CHUNK_SIZE;
this.gridStore = new GridStore(this.db, this.filename, 'r', this.options);
this.db.open(function(err){
if(err) throw err;
self.gridStore.open(function(err, gs){
if(err) throw err;
self.gridStore = gs;
self._read();
});
});
}
module.exports.getPdffile = function getPdffile(db, req, res) {
var fileid = req.params.fileid;
var objectId = mongo.ObjectID.createFromHexString(fileid);
var store = new mongo.GridStore(db, objectId, "r");
store.open(function(err, gs) {
if (err) {
res.send({ "Error": "Cannot open file, " + err });
} else {
var fileStream = gs.stream(true);
res.set("Content-Type", "application/pdf");
res.set("content-disposition", "attachment; filename=" + fileid + ".pdf");
fileStream.pipe(res);
}
});
}