From 5965db72a081d85b50b2188b228fa94a0dfa549d Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 5 Aug 2024 11:47:01 +0300 Subject: [PATCH 1/2] Document the complete event in README --- README.md | 8 +++++++- examples/tcp_metrics | 4 ---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 77aefd6..ecd30dd 100644 --- a/README.md +++ b/README.md @@ -208,7 +208,13 @@ If you no longer need to receive packets, you can use `pcap_session.close()`. To read packets from a file instead of from a live interface, use `createOfflineSession` instead: ```javascript -pcap.createOfflineSession('/path/to/capture.pcap', options); +const pcap_session = pcap.createOfflineSession('/path/to/capture.pcap', options); +pcap_session.on('packet', function (raw_packet) { + // do some stuff with a raw packet +}); +pcap_session.on('complete', function () { + // do some stuff when file ends +}); ``` Where `options` only accepts the `filter` property. diff --git a/examples/tcp_metrics b/examples/tcp_metrics index 7f38d79..94ef3da 100755 --- a/examples/tcp_metrics +++ b/examples/tcp_metrics @@ -20,10 +20,6 @@ pcap_session.on("packet", function (raw_packet) { tcp_tracker.track_packet(packet); }); -pcap_session.on("complete", function () { - console.log("pcap session complete."); -}); - // tracker emits sessions, and sessions emit data tcp_tracker.on("session", function (session) { console.log("Start of TCP session between " + session.src_name + " and " + session.dst_name); From e632822bfe61d85c46176ad70a9e0becd1b27a33 Mon Sep 17 00:00:00 2001 From: Orgad Shaneh Date: Mon, 5 Aug 2024 11:47:30 +0300 Subject: [PATCH 2/2] Rename complete event -> end --- README.md | 2 +- pcap.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index ecd30dd..bcc427b 100644 --- a/README.md +++ b/README.md @@ -212,7 +212,7 @@ const pcap_session = pcap.createOfflineSession('/path/to/capture.pcap', options) pcap_session.on('packet', function (raw_packet) { // do some stuff with a raw packet }); -pcap_session.on('complete', function () { +pcap_session.on('end', function () { // do some stuff when file ends }); ``` diff --git a/pcap.js b/pcap.js index 9675b65..b3db700 100644 --- a/pcap.js +++ b/pcap.js @@ -82,6 +82,7 @@ function PcapSession(is_live, device_name, filter, buffer_size, snap_length, out do { packets = this.session.dispatch(this.buf, this.header); } while ( packets > 0 ); + this.emit("end"); this.emit("complete"); }); }