Package Exports
- gridjs
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (gridjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
gridjs
A GridFS module that is easy to use and mongojs compliant. It is available through npm
npm install gridjs
Usage
It is easy to use
Connecting to Mongo/GridFS
To get started pass a connection string or mongojs instance to the gridjs constructor
var gridjs = require('gridjs');
var fs = require('fs');
var gs = gridjs('my-connection-string');
// or using a mongojs instance
var db = mongojs('my-connection-string');
var gs = gridjs(db);
// or using a node-mongodb-native instance
mongodb.Db.connect(connectionString, function(err, db) {
var gs = gridjs(db);
});
Writing files
Writing files using gridjs is a simple as piping to gs.createWriteStream(filename)
which returns a streams2 WriteStream
fs.createReadStream('any-file').pipe(gs.createWriteStream('gridfs-filename'));
Alternatively if you have the entire file as a single buffer you can use gs.write(filename, buffer, [enc], callback)
gs.write('test-file', new Buffer('hello world'), function(err) {
console.log('file is written', err);
});
Reading files
Similary when reading files you just pipe from gs.createReadStream(filename, [options])
which returns a streams2 ReadStream
gs.createReadStream('gridfs-filename').pipe(process.stdout);
There is also a gs.read(filename, [enc], callback)
shorthand if you want to read the entire file into a buffer
gs.read('test-file', function(err, buffer) {
console.log('file is read', buffer);
});