Skip to content

Commit

Permalink
Fixes README example, adds examples folder
Browse files Browse the repository at this point in the history
  • Loading branch information
LewisJEllis committed Jan 8, 2015
1 parent 4da909d commit f3650ab
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ var Grid = require('gridfs');
mongo.MongoClient.connect(yourMongoURI, function(err, db) {
var gfs = Grid(db, mongo);

var f = gfs.fromFile('./example.txt', {});
var f = gfs.fromFile({}, './example.txt');
console.log(f.id);
f.save(function (err, file) {
console.log('saved file');
gfs.readFile({_id: f.id}, function (err, data) {
console.log('read file: ' + data.toString());
});
});

gfs.writeFile({}, 'hello', function (err, file) {
console.log('wrote to ' + file._id);
});
});

gfs.readFile({_id: file.id}, function (err, data) {
console.log('read file:' + data.toString());
});
```

This is an extension of [gridfs-stream](https://github.com/aheckmann/gridfs-stream), building on its stream interface to provide additional utility methods. As such, huge props to [@aheckmann](https://github.com/aheckmann) and the rest of the contributors to gridfs-stream.
Expand Down
21 changes: 21 additions & 0 deletions examples/example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var mongo = require('mongodb');
var Grid = require('../index');

var yourMongoURI = 'mongodb://localhost:27017/gridfs-example'

mongo.MongoClient.connect(yourMongoURI, function(err, db) {
var gfs = Grid(db, mongo);

var f = gfs.fromFile({}, './example.txt');
console.log(f.id);
f.save(function (err, file) {
console.log('saved file');
gfs.readFile({_id: f.id}, function (err, data) {
console.log('read file: ' + data.toString());
});
});

gfs.writeFile({}, 'hello', function (err, file) {
console.log('wrote to ' + file._id);
});
});
1 change: 1 addition & 0 deletions examples/example.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
example

0 comments on commit f3650ab

Please sign in to comment.