mirror of
https://github.com/wassname/DefinitelyTyped.git
synced 2026-09-09 11:13:57 +08:00
Added gridfs-stream tests.
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
/// <reference path="gridfs-stream.d.ts" />
|
||||
/// <reference path="../mongodb/mongodb.d.ts" />
|
||||
/// <reference path="../node/node.d.ts" />
|
||||
|
||||
// Samples from:
|
||||
// https://github.com/aheckmann/gridfs-stream
|
||||
|
||||
import fs = require('fs');
|
||||
import mongo = require('mongodb');
|
||||
import Grid = require('gridfs-stream');
|
||||
|
||||
// create or use an existing mongodb-native db instance
|
||||
var db = new mongo.Db('gridfs-stream-test', new mongo.Server("127.0.0.1", 27017));
|
||||
var gfs = Grid(db, mongo);
|
||||
|
||||
// streaming to gridfs
|
||||
var writestream = gfs.createWriteStream({
|
||||
filename: 'my_file.txt'
|
||||
});
|
||||
fs.createReadStream('blob.txt').pipe(writestream);
|
||||
|
||||
// streaming from gridfs
|
||||
var readstream = gfs.createReadStream({
|
||||
filename: 'my_file.txt'
|
||||
});
|
||||
|
||||
//error handling, e.g. file does not exist
|
||||
readstream.on('error', function (err: any) {
|
||||
console.log('An error occurred!', err);
|
||||
throw err;
|
||||
});
|
||||
|
||||
var bufs: Array<any> = [];
|
||||
readstream.on('data', function(d: any){ bufs.push(d); });
|
||||
readstream.on('end', function() {
|
||||
var buf = Buffer.concat(bufs);
|
||||
});
|
||||
Vendored
+6
-6
@@ -51,13 +51,13 @@ declare module "gridfs-stream" {
|
||||
files: mongo.Collection;
|
||||
collection: mongo.Collection;
|
||||
|
||||
createWriteStream(options?: GridFSStream.Options) : GridFSStream.WriteStream;
|
||||
createReadStream(options?: GridFSStream.Options) : GridFSStream.ReadStream;
|
||||
createWriteStream(options?: string) : GridFSStream.WriteStream;
|
||||
createReadStream(options?: string) : GridFSStream.ReadStream;
|
||||
createWriteStream(options?: GridFSStream.Options): GridFSStream.WriteStream;
|
||||
createReadStream(options?: GridFSStream.Options): GridFSStream.ReadStream;
|
||||
createWriteStream(options?: string): GridFSStream.WriteStream;
|
||||
createReadStream(options?: string): GridFSStream.ReadStream;
|
||||
|
||||
remove(options: GridFSStream.Options, callback: (err: Error) => void);
|
||||
exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void);
|
||||
remove(options: GridFSStream.Options, callback: (err: Error) => void): void;
|
||||
exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void): void;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user