New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

albatross

Package Overview
Dependencies
Maintainers
1
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

albatross - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

lib/grid.js

41

lib/albatross.js

@@ -6,4 +6,7 @@ var util = require('util')

var Collection = require('./collection')
var Grid = require('./grid')
var ObjectID = mongodb.ObjectID
var GridStore = mongodb.GridStore
var GridFSBucket = mongodb.GridFSBucket
var EventEmitter = events.EventEmitter

@@ -18,2 +21,4 @@ var MongoClient = mongodb.MongoClient

this._colCache = {}
this._grids = {}
this._gridCache = {}
this.connected = false

@@ -36,4 +41,12 @@ this.connecting = true

Albatross.prototype._whenConnected = function (cb) {
if (this.connected) {
cb.call(this)
} else {
this.once('connected', cb.bind(this))
}
}
Albatross.prototype._getRawCollection = function (name, cb) {
function whenConnected () {
this._whenConnected(function whenConnected () {
if (this._colCache.hasOwnProperty(name) === false) {

@@ -44,9 +57,13 @@ this._colCache[name] = this._dbInstance.collection(name)

return cb(this._colCache[name])
}
})
}
if (this.connected) {
whenConnected.call(this)
} else {
this.once('connected', whenConnected.bind(this))
}
Albatross.prototype._getRawGrid = function (name, cb) {
this._whenConnected(function whenConnected () {
if (this._gridCache.hasOwnProperty(name) === false) {
this._gridCache[name] = new GridFSBucket(this._dbInstance, { bucketName: name })
}
return cb(this._gridCache[name])
})
}

@@ -68,2 +85,12 @@

Albatross.prototype.grid = function (name) {
if (!name) name = GridStore.DEFAULT_ROOT_COLLECTION
if (!this._grids.hasOwnProperty(name)) {
this._grids[name] = new Grid(this, name)
}
return this._grids[name]
}
Albatross.prototype.close = function (cb) {

@@ -70,0 +97,0 @@ function done (err) {

7

package.json
{
"name": "albatross",
"version": "1.0.0",
"version": "1.1.0",
"license": "MIT",

@@ -19,9 +19,10 @@ "author": "Linus Unnebäck <linus@folkdatorn.se>",

"debug": "^2.2.0",
"mongodb": "^2.0.33"
"mongodb": "^2.1.0"
},
"devDependencies": {
"array-includes": "^3.0.0",
"concat-stream": "^1.5.1",
"mocha": "^2.2.5",
"standard": "^5.1.0"
"standard": "^6.0.5"
}
}

@@ -16,6 +16,6 @@ # ![Albatross](/header.png?raw=true "Albatross")

```js
var albatross = require('albatross');
var albatross = require('albatross')
var db = albatross('mongodb://localhost/test');
var user = db.collection('user');
var db = albatross('mongodb://localhost/test')
var user = db.collection('user')

@@ -26,6 +26,25 @@ user

.findOne({ born: 1992 }, function (err, doc) {
if (err) { throw err; }
if (err) throw err
console.log('Hello ' + doc.name);
});
console.log('Hello ' + doc.name)
})
var fs = require('fs')
var grid = db.grid()
var input = fs.createReadStream('README.md')
var opts = { filename: 'README.md', contentType: 'text/plain' }
grid.upload(input, opts, function (err, id) {
if (err) throw err
grid.download(id, function (err, result) {
if (err) throw err
result.filename // 'README.md'
result.contentType // 'text/plain'
result.stream.pipe(process.stdout)
})
})
```

@@ -71,2 +90,7 @@

#### `.grid([name])`
Returns a new instance of Grid, optionally using the supplied `name` as the
name of the root collection.
#### `.id(strOrObjectID)`

@@ -129,2 +153,48 @@

### Grid
#### `id(strOrObjectID)`
Makes sure that the given argument is an ObjectID.
#### `upload(stream[, opts][, cb]) -> (err, result)`
Store the `stream` as a file in the grid store, `opts` is a object with the
following properties. All options are optionally.
- `filename`: The value of the `filename` key in the files doc
- `chunkSizeBytes`: Overwrite this bucket's `chunkSizeBytes` for this file
- `metadata`: Object to store in the file document's `metadata` field
- `contentType`: String to store in the file document's `contentType` field
- `aliases`: Array of strings to store in the file document's `aliases` field
The `result` object has the following properties:
- `id`: The id of the file
- `md5`: The md5 hash of the file
- `length`: The length of the file
- `chunkSize`: The size of each chunk in bytes
- `filename`: The value of the `filename` key in the files doc
- `metadata`: An object with the metadata associated with the file
- `contentType`: The value of the `contentType` key in the files doc
#### `download(id[, cb]) -> (err, result)`
Get the file with the specified `id` from the grid store. The callback will
receive a `result` object with the following properties. If no file with the
indicated `id` was found, `result` will be `null`.
- `id`: The id of the file
- `md5`: The md5 hash of the file
- `length`: The length of the file
- `chunkSize`: The size of each chunk in bytes
- `filename`: The value of the `filename` key in the files doc
- `metadata`: An object with the metadata associated with the file
- `contentType`: The value of the `contentType` key in the files doc
- `stream`: The stream with the data that was inside the file
#### `delete(id[, cb]) -> (err)`
Delete the file with the specified `id` from the grid store.
## In depth documentation

@@ -131,0 +201,0 @@

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