diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index f897e263ef..426449ac05 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -88,6 +88,7 @@ All definitions files include a header with the author and editors, so at some p * [GoJS](http://gojs.net/) (by [Barbara Duckworth](https://github.com/barbara42)) * [Greasemonkey](http://www.greasespot.net/) (by [Kota Saito](https://github.com/kotas)) * [GreenSock Animation Platform (GSAP)](http://www.greensock.com/get-started-js/) (by [Robert S.](https://github.com/codeBelt)) +* [gridfs-stream](https://github.com/aheckmann/gridfs-stream) (by [Lior Mualem](https://github.com/liorm)) * [Grunt JS](http://gruntjs.com/) (by [Jeff May](https://github.com/jeffmay), [Basarat Ali Syed](https://github.com/basarat) and [San Chen](https://github.com/bigsan)) * [Google API Client](https://code.google.com/p/google-api-javascript-client/) (by [Frank M](https://github.com/sgtfrankieboy)) * [Google App Engine Channel API](https://developers.google.com/appengine/docs/java/channel/javascript) (by [vvakame](https://github.com/vvakame)) diff --git a/express/express.d.ts b/express/express.d.ts index 562dbf3013..eafc4c5966 100644 --- a/express/express.d.ts +++ b/express/express.d.ts @@ -240,7 +240,7 @@ declare module "express" { count: number; } - interface Request extends Express.Request { + interface Request extends http.ServerRequest, Express.Request { session: Session; diff --git a/gridfs-stream/gridfs-stream-tests.ts b/gridfs-stream/gridfs-stream-tests.ts new file mode 100644 index 0000000000..c9ca457c2a --- /dev/null +++ b/gridfs-stream/gridfs-stream-tests.ts @@ -0,0 +1,37 @@ +/// +/// +/// + +// 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 = []; +readstream.on('data', function(d: any){ bufs.push(d); }); +readstream.on('end', function() { + var buf = Buffer.concat(bufs); +}); diff --git a/gridfs-stream/gridfs-stream.d.ts b/gridfs-stream/gridfs-stream.d.ts new file mode 100644 index 0000000000..a8ad5f9ed3 --- /dev/null +++ b/gridfs-stream/gridfs-stream.d.ts @@ -0,0 +1,68 @@ +// Type definitions for gridfs-stream 0.5.0 +// Project: https://github.com/aheckmann/gridfs-stream +// Definitions by: Lior Mualem +// Definitions: https://github.com/borisyankov/DefinitelyTyped + +/// +/// + +declare module GridFSStream { + export interface Range { + startPos: number; + endPos: number; + } + + export interface Options { + _id?: string; + filename?: string; + mode?: string; + + range?: Range; + + // any other options from the GridStore may be passed too, e.g. + chunkSize?: number; + content_type?: string; + root?: string; + metadata?: any; + } + + export interface WriteStream extends NodeJS.WritableStream { + writable: boolean; + name: string; + id: string; + options: Options; + mode: string; + } + + export interface ReadStream extends NodeJS.ReadableStream { + readable: boolean; + paused: boolean; + } +} + +declare module "gridfs-stream" { + import mongo = require('mongodb'); + + // Merged declaration, g is both a callable function and a namespace + function g(db: any, mongo: any): g.Grid; + + module g { + + export class Grid { + + files: mongo.Collection; + collection(name?: string): mongo.Collection; + + 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): void; + exist(options: GridFSStream.Options, callback: (err: Error, found: boolean) => void): void; + } + } + + export = g; +} +