Carbon
seedalpha's persistence layer
In order to prevent mutation Seedalpha's infrastructure runs on a read-only filesystem. Carbon's role is to persist services output.
Changelog
2.1.3
:
- remove
s3-streams
2.1.2
:
- update
s3-writeable
2.1.1
:
- use
s3-readable
,s3-writeable
2.1.0
:
- expose carbon app / lib / standalone
- integration tests
- clean server
- update docs
2.0.2
:
- setup npm to use NPM_AUTH
- test coverage
- streaming uploads / downloads
2.0.1
:
- ci integration
2.0.0
:
- Major API changes
- Standalone use
- Library use
Prerequisites (standalone)
-
NPM_AUTH
-
AUTH
-
PORT
-
AMAZON_ACCESS_KEY_ID
-
AMAZON_ACCESS_KEY_SECRET
-
S3_REGION
-
S3_BUCKET
or -
DATABASE_URL
Development
$ git clone git@github.com:seedalpha/carbon.git
$ cd carbon
$ npm install
$ npm test
Usage
# index.js
var Carbon = require('seed-carbon');
// persist in mongodb GridFS
var store = new Carbon({
adapter: Carbon.MongoAdapter('mongodb://localhost:27017/carbon')
});
// or in AWS S3
var store = new Carobn({
adapter: Carbon.S3Adapter({
key: AWS_ACCESS_KEY_ID,
secret: AWS_ACCESS_KEY_SECRET,
region: 'ap-southeast-1',
bucket: 'carbon'
})
});
// API
store.put({
filename: 'research.pdf',
contentType: 'application/pdf',
stream: fs.createReadStream('./research.pdf')
}, function(error){ });
store.get('research.pdf', function(error, file) {
file.length
file.filename
file.contentType
file.stream
});
store.remove('research.pdf', function(error) {});
Usage with express
# index.js
var express = require('express);
var CarbonServer = require('seed-carbon/server');
var config = {
auth: 'abcd',
key: process.env.AMAZON_ACCESS_KEY_ID,
secret: process.env.AMAZON_ACCESS_KEY_SECRET,
region: process.env.S3_REGION,
bucket: process.env.S3_BUCKET,
// or
db: process.env.DATABASE_URL
};
var carbonServer = CarbonServer(config);
var app = express();
app.use('/store', carbonServer);
app.listen(process.env.PORT || 5000);
// same as library usage
var store = carbonServer.carbon;
// $ curl -F file=some-file.txt http://127.0.0.1/store/some-file.txt
Standalone usage
$ git clone git@github.com:seedalpha/carbon.git
$ cd carbon
$ npm install
$ export PORT=5000
$ export AUTH=zzz
$ export DEBUG=carbon* # optional
$ # for S3
$ export AWS_ACCESS_KEY_ID=xxx
$ export AWS_ACCESS_KEY_SECRET=yyy
$ export S3_REGION=ap-southeast-1
$ export S3_BUCKET=carbon
$ # or for GridFS
$ export DATABASE_URL=mongodb://localhost:27017/carbon
$ npm start
# in a second shell
$ curl -XPOST -H 'Content-Type: application/pdf' --data-binary @spec/document.pdf http://127.0.0.1:5000/document.pdf
$ curl -F file=@spec/document.pdf http://127.0.0.1:5000/document.pdf
$ open http://127.0.0.1:5000/document.pdf # should open in a reader
Author
Vladimir Popov vlad@seedalpha.net
License
©2014 Seedalpha