Note: this module is auto published to npm on CircleCI. Only run npm version patch|minor|major
and let CI do the rest.
sci.pe blob store powered by the abstract-blob-store API with a zest of schema.org.
import BlobStore from '@scipe/blob-store';
let store = new BlobStore({
store: 'S3', // or 'fs'
apiPathnamePrefix: 'http://example.com/'
});
store.put({
body: fs.createReadStream('pieuvre.png'), // body can also be a string or a Buffer
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: 'encodingId'
}, (err, encoding, params) => {
console.log(encoding);
});
or
store.put({
path: 'pieuvre.png',
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: 'encodingId'
}, (err, encoding, params) => {
console.log(encoding);
});
or
let readStream = fs.createReadStream('data.csv');
let writeStream = store.put({
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: 'encodingId'
}, (err, encoding, params) => {
console.log(encoding);
});
readStream.pipe(writeStream);
encoding
is a schema.org MediaObject or subclass thereof e.g.,
{
'@id': 'encodingId',
'@type': 'ImageObject',
creator: 'bot:BlobStore',
fileFormat: 'image/png',
contentSize: 20402,
name: 'pieuvre.png',
contentUrl: 'http://example.com/encodingId',
encodesCreativeWork: 'resourceId',
dateCreated: '2015-04-17T15:37:00.528Z',
contentChecksum: {
'@type': 'Checksum',
checksumAlgorithm: 'sha256',
checksumValue: 'DmjKGM5ZHmyeDdVxUpoCADhybkfISowriovdhgbXVBA='
}
}
An encoding
(schema.org MediaObject
or subclass thereof) can be passed as the first paramater and params
used to overwrite parameters (graphId
, resourceId
, encodingId
)
that can be extracted from the encoding.
let readStream = store.get({
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: 'encodingId'
});
or
store.get({
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: 'encodingId'
}, (err, body) => {
// body is a Buffer
});
Delete a blob:
store.delete({
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: 'encodingId'
}, (err, action, params) => {
});
Delete all the blobs of a resource:
store.delete({
graphId: 'graphId',
resourceId: 'resourceId',
encodingId: null
}, (err, action, params) => {
});
Delete all the blobs of a graph:
store.delete({
graphId: 'graphId',
resourceId: null,
encodingId: null
}, (err, action, params) => {
});
@scipe/blob-store
is dual-licensed under commercial and open source licenses
(AGPLv3) based on the intended
use case. Contact us to learn which license applies to your use case.