UNPKG

1.48 kBMarkdownView Raw
1
2# gridfs-stream
3
4Easily stream files to and from MongoDB [GridFS](http://www.mongodb.org/display/DOCS/GridFS).
5
6```js
7var gfs = require('gridfs-stream')(db);
8
9// streaming to gridfs
10var writestream = gfs.createWriteStream('filename');
11fs.createReadStream('/some/path').pipe(writestream);
12
13// streaming from gridfs
14var readstream = gfs.createReadStream('filename');
15readstream.pipe(response);
16```
17
18Created streams are compatible with other Node streams so piping anywhere is easy.
19
20## install
21
22```
23npm install gridfs-stream
24```
25
26## use
27
28The `gridfs-stream` module exports a function that accepts a [mongodb-native](https://github.com/mongodb/node-mongodb-native/) db. The db must already be opened before passing it in.
29
30```js
31var gfs = require('gridfs-stream')(db);
32```
33
34Now we're ready to start streaming.
35
36## createWriteStream
37
38To stream data to GridFS we call `createWriteStream` passing a filename and any options.
39
40```js
41var writestream = gfs.createWriteStream('filename' [, options]);
42fs.createReadStream('/some/path').pipe(writestream);
43```
44
45## createReadStream
46
47To stream data out of GridFS we call `createReadStream` passing a filename and any options.
48
49```js
50var readstream = gfs.createReadStream('filename' [, options]);
51readstream.pipe(response);
52```
53
54Any options are passed to the internally created [GridStore](http://mongodb.github.com/node-mongodb-native/api-generated/gridstore.html).
55
56[LICENCE](https://github.com/aheckmann/gridfs-stream/blob/master/LICENSE)