File: on.md

package info (click to toggle)
node-jszip 3.5.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 25,100 kB
  • sloc: javascript: 5,652; makefile: 2; sh: 2
file content (54 lines) | stat: -rw-r--r-- 1,293 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: "on(event, callback)"
layout: default
section: api
---

Register a listener on an event.

__Returns__ : The current StreamHelper object, for chaining.

__Throws__ : An exception if the event is unknown.

## Arguments

name      | type     | description
----------|----------|------------
event     | string   | the name of the event. Only 3 events are supported : `data`, `end` and `error`.
callback  | function | the function called when the event occurs. See below for the arguments.

The callbacks are executed in with the current `StreamHelper` as `this`.

### `data` callback

It takes 2 parameters:

- the current chunk of data (in a format specified by the method which
  generated this StreamHelper)
- the metadata (see each method to know what's inside)

### `end` callback

It does not take any parameter.

### `error` callback

It takes an `Error` as parameter.

## Example

```js
zip
.generateInternalStream({type:"uint8array"})
.on('data', function (data, metadata) {
    // data is a Uint8Array because that's the type asked in generateInternalStream
    // metadata contains for example currentFile and percent, see the generateInternalStream doc.
})
.on('error', function (e) {
    // e is the error
})
.on('end', function () {
    // no parameter
})
.resume();
```