index.js
function loadAttachments (doc, directory, callback) {
  doc._attachments = doc._attachments || {};
  glob('**/*', { cwd: directory }, function (err, files) {
    async.each(files, function (file, done) {
      if (file.indexOf('_') === 0) return done();
      fs.stat(path.join(directory, file), function (err, stat) {
        if (err) return done(err);
        if (stat.isFile()) {
          fs.readFile(path.join(directory, file), function (err, data) {
            if (err) return done(err);
            var ext = file.split('.').pop()
            doc._attachments[file] = {}
            doc._attachments[file]['content_type'] = lookup(ext);
            doc._attachments[file]['data'] = data.toString('base64');
            done();
          });
        } else {
          done();
        }
      });
    }, function (err) {
      callback.call(null, err, doc);
    });
  });
}
function loadAttachments (doc, directory, callback) {
  doc._attachments = doc._attachments || {};
  glob('**/*', { cwd: directory }, function (err, files) {
    async.each(files, function (file, done) {
      if (file.indexOf('_') === 0) return done();
      fs.stat(path.join(directory, file), function (err, stat) {
        if (err) return done(err);
        if (stat.isFile()) {
          fs.readFile(path.join(directory, file), function (err, data) {
            if (err) return done(err);
            var ext = file.split('.').pop()
            doc._attachments[file] = {}
            doc._attachments[file]['content_type'] = lookup(ext);
            doc._attachments[file]['data'] = data.toString('base64');
            done();
          });
        } else {
          done();
        }
      });
    }, function (err) {
      callback.call(null, err, doc);
    });
  });
}
function loadAttachments ( doc , directory , callback ) { doc . _attachments = doc . _attachments || { } ; glob ( '**/*' , { cwd : directory } , function ( err , files ) { async . each ( files , function ( file , done ) { if ( file . indexOf ( '_' ) === 0 ) return done ( ) ; fs . stat ( path . join ( directory , file ) , function ( err , stat ) { if ( err ) return done ( err ) ; if ( stat . isFile ( ) ) { fs . readFile ( path . join ( directory , file ) , function ( err , data ) { if ( err ) return done ( err ) ; var ext = file . split ( '.' ) . pop ( ) doc . _attachments [ file ] = { } doc . _attachments [ file ] [ 'content_type' ] = lookup ( ext ) ; doc . _attachments [ file ] [ 'data' ] = data . toString ( 'base64' ) ; done ( ) ; } ) ; } else { done ( ) ; } } ) ; } , function ( err ) { callback . call ( null , err , doc ) ; } ) ; } ) ; }
Recursively load attachments from a directory onto
a design document.

@param {object} doc design document
@param {string} directory path to the attachments directory
@param {function} callback (err, document)
Recursively load attachments from a directory onto a design document .