hyperdrive-jpeg-index
v1.1.0
Published
index jpeg metadata and thumbnails for a hyperdrive archive
Downloads
4
Maintainers
Readme
hyperdrive-jpeg-index
index jpeg metadata and thumbnails for a hyperdrive archive
example
This example will store time
and orientation
values from EXIF headers and
width
and height
values from SOF headers.
var hyperdrive = require('hyperdrive')
var fs = require('fs')
var path = require('path')
var sub = require('subleveldown')
var to = require('to2')
var jpeg = require('hyperdrive-jpeg-index')
var level = require('level')
var db = level('/tmp/photos.db')
var namedArchives = require('hyperdrive-named-archives')
var named = namedArchives({
drive: hyperdrive(sub(db, 'drive')),
db: sub(db, 'archives')
})
var archive = named.createArchive('photos')
var photos = jpeg({
archive: archive,
db: sub(db, 'jpeg'),
properties: {
time: ['EXIF','exif','DateTimeOriginal',isoString],
orientation: ['EXIF','image','Orientation'],
width: ['SOF','width'],
height: ['SOF','height']
}
})
function isoString (date) { return date.toISOString() }
if (process.argv[2] === 'add') {
var file = process.argv[3]
fs.createReadStream(file)
.pipe(archive.createFileWriteStream(path.basename(file)))
} else if (process.argv[2] === 'list') {
photos.list().pipe(to.obj(function (img, enc, next) {
console.log(img)
}))
}
output:
$ node photos.js add cactus.jpg
$ node photos.js list
{ name: 'cactus.jpg',
properties:
{ time: '2015-06-19T16:40:52.000Z',
orientation: 1,
width: 600,
height: 800 } }
api
var jpeg = require('hyperdrive-jpeg-index')
var photos = jpeg(opts)
Create a photos
instance from:
opts.archive
- a hyperdrive archiveopts.db
- a leveldb instance to save index dataopts.properties
- map of property keys to marker key pathsopts.map(entry, stream, next)
- intercept the entry and binary jpeg stream
Each marker key path given in opts.properties
is an array that describes the
nested location into a marker object to produce a value. Key path items can
be a string or a function (node) {}
that take an object as input and should
return the next node value to use in the traversal.
With opts.map
you can calculate secondary indexes or set additional
properties. Call next(err, props)
with any additional properties to set on the
record. You can use opts.map
to do things like generate resized versions of
the image to store elsewhere.
var stream = photos.list()
Return a readable objectMode stream
of records. Each record has:
row.name
- file name from hyperdriverow.properties
- the values generated from the marker key paths
photos.get(name, cb)
Fetch the property values generated for a file name
.
install
npm install hyperdrive-jpeg-index
license
BSD