Skip to content

Instantly share code, notes, and snippets.

@mk-pmb
Created August 21, 2016 11:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mk-pmb/b1d95d2e8fb8d64024ae064e48513daf to your computer and use it in GitHub Desktop.
Save mk-pmb/b1d95d2e8fb8d64024ae064e48513daf to your computer and use it in GitHub Desktop.
Promisify with control over selection, names and target.
/*jslint indent: 2, maxlen: 80, node: true */
/* -*- tab-width: 2 -*- */
'use strict';
var EX = module.exports, Promise = require('bluebird'), origFs = require('fs');
Object.keys(origFs).forEach(function customPromisify(key) {
var slot = origFs[key];
if (slot instanceof Function) {
if (key.match(/Sync$/)) { return; }
if (key.match(/Stream$/)) { return; }
slot = Promise.promisify(slot.bind(origFs));
}
EX[key] = slot;
});
EX.readFile(module.filename, 'utf-8').then(function (data) {
console.dir(EX);
console.log(data.length);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment