ncb000gt/node-gs — pull request #3 by ecarter (2012-12-05 01:58:07+00:00)
Title: support for events

Doing some work on calculating pdf conversion times :hourglass: progress complete, and needed some help from `EventEmitter`.

Didn't plan on this being such a large refactor to implement events, so **wanted to run it by you first** to get your thoughts.

Line-per-line a lot has changed but made sure the api and current functionality stayed exactly the same.

Let me know what you think :eyes:

---

**#on(event, callback...)** - adds event listener to a `gs` instance

**Events:**

* `data` - emitted when data is received _(stdout)_
* `pages` - when page processing begins
* `page` - on **each** page process

### Examples

**.on('data', fn)** - callback gets `data` argument _(stdout)_

```
gs()
.nodisplay()
.input('./tests/pdfs/sizes.pdf')
.on('data', function(data){
console.log(data);
})
.exec(function(err, data){
// do stuff...
});
```

**.on('pages', fn)** - callback gets `from` _(first page)_ and `to` _(last page)_

```
gs()
.input('./tests/pdfs/sizes.pdf')
.output('./test/pdfs/sizes-%d.jpg')
.on('pages', function(from, to) {
console.log("processing pages %s to %s", from, to);
})
.exec(function(err, data){
// do stuff...
});
```

**.on('page', fn)** - callback gets `page` _(number of current page process)_

```
gs()
.input('./tests/pdfs/sizes.pdf')
.output('./test/pdfs/sizes-%d.jpg')
.on('page', function(page) {
console.log("page %s complete", page);
})
.exec(function(err, data){
// do stuff...
});
```

---

**Changed:**

* `gs` now inherits `EventEmitter`
* moved static methods to prototypes
* added aliases
* `.p()` => `.currentDirectory()`
* `.q()` => `.quiet()`
* `.r()` and `.res()` => `.resolution()`
* added tests / updated test suits
* spaces to tabs globally

**Todo:**

* docs
* more examples

---

Really appreciate you putting this lib together, has been a major jump-start for me on new project and enjoy contributing back.