The GridFS wrapper module for Node.js.
var fs = ;var mongo = ;var Grid = ;mongoMongoClient;
This is a simple extension of the excellent gridfs-stream library, building on its stream interface to provide additional utility methods. As such, huge props to @aheckmann and the rest of the contributors to gridfs-stream.
gridfs can be used as a drop-in replacement for
gridfs-stream, as it exports the same object as
gridfs-stream, just with additional methods available.
npm install gridfs
options fields are the same as
options fields in gridfs-stream; they're just passed along to the stream constructors.
gfs.readFile(options, cb(err, buffer))
Get the contents of the GridFS file specified by
gfs.writeFile(options, data, cb(err, file))
data to the GridFS file specified by
data can be a String or a Buffer.
gfs.toFile(options, target, cb(err))
Read from the GridFS file specified by
options and write its contents to
target can be a file path or writable stream.
gfs.fromFile(options, source, cb(err, file))
source and write its contents to the GridFS file specified by
source can be a file path or readable stream.
Returns the GridFS writeStream used for writing the file.
Gets the list of files stored in GridFS, using GridStore.list.
Notes on other potentially desirable
fs.stat- use gfs.findOne
fs.unlink- use gfs.remove
fs.exists- use gfs.exist
fs.createReadStream- use gfs.createReadStream
fs.createWriteStream- use gfs.createWriteStream
fs.appendFile- not currently feasible due to risk of corruption from parallel writes; see MongoDB driver 2.0 notes
Pull requests are welcome. Guidelines: make sure
npm test passes.
eslint, and mongo to run the tests; they use the
gridfs-mocha-test database on the local mongo server.