r2pipe-promise
promisified r2pipe api
Last updated a year ago by pancake .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install r2pipe-promise 
SYNC missed versions from official npm registry.

r2pipe-promise

The r2pipe-promise is a frontend for the r2pipe module that provides a promisified API that can be used with co, bluebird or just in plain Javascript using the .then, .catch methods.

This allows to create cleaner and better asynchronous scripts without making the whole logic.

This is an example:

const r2promise = require('r2pipe-promise');
r2promise.open('/bin/ls')
.then(r2 => {
  r2.cmd('?E hello world')
  .then(res => {
    console.log(res);
    r2.quit();
  })
  .catch(console.error);
})
.catch(console.error);

Another example using the co module:

const r2promise = require('r2pipe-promise');
const co = require('co');

co(function * () {
  try {
    const r2 = yield r2promise.open('/bin/ls');
    console.log('This is', yield r2.cmd('o'));
    yield r2.quit();
  } catch (e) {
    console.error('error', e);
    process.exit(1);
  }
});

You can achieve the same using bluebird in exchange of having more dependencies and verboser code.

const Promise = require('bluebird');
const r2pipe = Promise.promisifyAll(require('r2pipe'));

r2pipe.openAsync('/bin/ls').then(r => {
  const r2 = Promise.promisifyAll(r);
  r2.cmdAsync('?E hello').then(msg => {
    console.log(msg);
    r2.quitAsync();
  });
})
.catch(err => {
  console.error(err.message);
});
~

Since node 7.6 there is default support for Async/Await, so now we can use it to write more cleaner and legible code, for example:

const r2promise = require('r2pipe-promise');

const radare2FTW = async () => {
  try {
    const r2 = await r2promise.open('/bin/ls');
    const msg = await r2.cmd('?E hello world');
    console.log(msg);
    return r2.quit();
  } catch (err) {
    console.error(err);
  }
}

// Call function
radare2FTW();

Current Tags

  • 1.5.1                                ...           latest (a year ago)

10 Versions

  • 1.5.1                                ...           a year ago
  • 1.5.0                                ...           a year ago
  • 1.4.1                                ...           2 years ago
  • 1.4.0                                ...           2 years ago
  • 1.3.0                                ...           2 years ago
  • 1.2.1                                ...           3 years ago
  • 1.2.0                                ...           3 years ago
  • 1.1.0                                ...           3 years ago
  • 1.0.1                                ...           3 years ago
  • 1.0.0                                ...           3 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 1
Last Month 3
Dependencies (1)
Dev Dependencies (1)

Copyright 2014 - 2016 © taobao.org |