1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 | var GridWriteStream = require('./writestream')
|
8 | var GridReadStream = require('./readstream')
|
9 |
|
10 | module.exports = exports = function gridfsStream (mongo) {
|
11 | function Grid (db) {
|
12 | if (!(this instanceof Grid)) {
|
13 | return new Grid(db);
|
14 | }
|
15 |
|
16 |
|
17 | this.db = db;
|
18 | this.mongo = mongo;
|
19 | this.tryParseObjectId = tryParseObjectId;
|
20 | }
|
21 |
|
22 | Grid.prototype.createWriteStream = function (filename, options) {
|
23 | return new GridWriteStream(this, filename, options);
|
24 | }
|
25 |
|
26 | Grid.prototype.createReadStream = function (filename, options) {
|
27 | return new GridReadStream(this, filename, options);
|
28 | }
|
29 |
|
30 | return Grid;
|
31 | }
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 |
|
41 | function tryParseObjectId (string) {
|
42 | try {
|
43 | return new this.mongo.BSONPure.ObjectID(string);
|
44 | } catch (_) {
|
45 | return false;
|
46 | }
|
47 | }
|