Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@gradecam/gridfs

Package Overview
Dependencies
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@gradecam/gridfs

Make working with GridFS and mongoose easier.

  • 1.1.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
4
decreased by-20%
Maintainers
5
Weekly downloads
 
Created
Source

@gradecam/gridfs

Makes working with GridFS just a little bit easier.

Installation

$ npm install --save @gradecam/gridfs

Usage

Direct usage of GridFSBucket

import { createReadStream } from 'fs';

import mongodb from 'mongodb';
import { GridFSBucket, WriteFileOpts } from '@gradecam/gridfs';

async function main() {
  const client = await mongodb.connect('mongodb://localhost/gcgfs', {useNewUrlParser: true});
  const db = client.db();
  const bucket = new GridFSBucket(db);
  // write file to gridfs
  const readStream = createReadStream('sample.txt');
  const options: WriteFileOpts = { filename: 'sample.txt', contentType: 'text/plain' };
  const file = await bucket.writeFile(options, readStream);
  if (file) {
    const fileBuff = await bucket.readFile({_id: file._id});
    // ... do something with fileBuff
  }
  client.close();
}

Usage with mongoose

import { createReadStream } from 'fs';

import mongoose from 'mongoose';
import { BucketFile, createFileSchema } from '@gradecam/gridfs';

async function main() {
  await mongoose.connect('mongodb://localhost/gcgfs', {useNewUrlParser: true});
  const schema = createFileSchema('attachments');
  const AttachmentFile = mongoose.model('AttachmentFile', schema);
  // write file to gridfs
  const readStream = createReadStream('sample.txt');
  const fileOpts: Partial<BucketFile> = { filename: 'sample.txt', contentType: 'text/plain' };
  const doc = await AttachmentFile.write(fileOpts, readStream);
  const fileBuff = await doc.read();
  // ... do something with fileBuff
  mongoose.disconnect();
}

Credits

Package was inspired by mongoose-gridfs

Notable changes from mongoose-gridfs include:

  • Package dependencies kept to a minimum
  • Can define Mongoose Schema and Model's without having an established connection
  • First class TypeScript support

Keywords

FAQs

Package last updated on 23 Sep 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc