How to use the mongodb.GridStore function in mongodb

To help you get started, we’ve selected a few mongodb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github siddMahen / GridFS / lib / GridFS.js View on Github external
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');
                    });
github parse-community / parse-server / src / Adapters / Files / GridStoreAdapter.js View on Github external
.then(database => {
        const gridStore = new GridStore(database, filename, 'r');
        return gridStore.open();
      })
      .then(gridStore => {
github seedalpha / express-file-store / lib / express-file-store / backends / gridfs.js View on Github external
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);
}
github exi / soupcache / mongocache.js View on Github external
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);
        });
    };
github exi / soupcache / mongocache.js View on Github external
var openDbFileRead = function(filename, cb) {
        var gridstore = new GridStore(
            db,
            filename,
            'r',
            {
                root: rootCollection
            }
        );

        gridstore.open(function(err, gs) {
            cb(gs);
        });
    };
github kissjs / node-mongoskin / lib / grid_store.js View on Github external
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);
  });
}
github jsreport / jsreport / lib / blobStorage / gridFSBlobStorage.js View on Github external
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);
            }
        });
    });
};
github kissjs / node-mongoskin / lib / grid_store.js View on Github external
skindb.open(function(err, p_db) {
        args[0] = p_db;
        GridStore[methodName].apply(GridStore, args);
    });
  }
github siddMahen / GridFS / lib / GridStream.js View on Github external
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();
        });
    });
}
github bthorben / pdfRepo / core / pdfs.js View on Github external
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);
    }
  });
}