Home

Awesome

level-vinyl

leveldb vinyl adapter and blob store. Saves file contents in a content addressable blob store, file metadata in leveldb. Supports globbing, most of the gulp 4.0 options and emits streaming vinyl files.

npm status Travis build status AppVeyor build status Dependency status

Jump to: example / usage / vinyl adapter api / levelup api / install / license

why?

Because level-vinyl is a vinyl adapter, you can:

Because level-vinyl saves metadata (stat, digest and custom properties) to leveldb by a virtual path, you can:

example

var levelvinyl = require('level-vinyl')
  , level      = require('level-test')()
  , sublevel   = require('level-sublevel')
  , buffer     = require('vinyl-buffer')
  , imagemin   = require('imagemin-jpegtran')()
  , vfs        = require('vinyl-fs')

// Create database
var db = level();
var sdb = sublevel(db, { valueEncoding: 'json'});
var vinylDb = levelvinyl(sdb, './example/blobs')

// Create a sublevel for minified images
var min  = vinylDb.subvinyl('minified').dest('/')
var main = vinylDb.dest('/')

vfs.src('*.jpg')     // file.contents is a buffer
  .pipe(main)        // save to db
  .pipe(imagemin())  // minify
  .pipe(min)         // save minified to db

Same thing, other way around:

var min  = vfs.dest('./example/minified')
var main = vfs.dest('./example')

vinylDb.src('*.jpg') // file.contents is a stream
  .pipe(main)        // copy to fs
  .pipe(buffer())    // imagemin wants buffers
  .pipe(imagemin())  // minify
  .pipe(min)         // copy minified to fs

Note though, it's a levelup database:

vinylDb.get('/example.jpg', function(err, file){
  file.contents.pipe(somewhere)
})

vinylDb.get('/example.jpg', { read: false }, function(err, file){
  console.log( file.isNull() === true )
})

usage

levelVinyl(db, options || path)

If you provide an options object, it will be passed to content-addressable-blob-store.

vinyl adapter api

The items below are described in terms of compatibility with vinyl-fs.

db.src(pattern(s)[, options])

Differences

Features

Missing / partial support

db.dest([path][, options])

Differences

Features

Missing / partial support

db.watch([pattern(s)][, options][, cb])

Differences

Features

Returns an emitter with these events:

And these methods:

levelup api

db.get(path[, options], cb)

Get a single file. path will be made absolute and unixified.

db.get('/images/moon.png', cb) // i like this
db.get('images\\moon.png', cb) // but this is fine too

db.subvinyl(prefix[, options])

Create a sublevel and install level-vinyl - the sublevel will have its own blob store. Prefix and options are passed to sublevel.

db.put(key, vinyl[, options][, cb])

db.put(vinyl[, options][, cb])

Save a single file.

db.del(key[, cb])

Nothing special, except this again:

db.del('/document') == db.del('\\document')

db.batch(ops[, options], cb)

For put operations:

db.batch([{
  type: 'put',
  key: '/project/readme',
  value: readmeFile,
  mode: 0755
}])

db.createReadStream([options])

This is a plain stream, i.e. it does not decode values to Vinyl files.

db.getBlobStore()

Get the blob store instance.

install

With npm do:

npm install level-vinyl

license

MIT © Vincent Weevers