Main module for working with PCAP and PCAPNG streams.

module:pcap :Object

Constants specific to the PCAPNG format.

Methods

(inner) createReadStream(optionsopt) → {PcapInputStream|PcapNGInputStream}

Creates a readable stream for network packets from PCAP or PCAPNG formats.
Parameters:
NameTypeAttributesDefaultDescription
optionsObject<optional>
{}Options for creating the read stream.
Properties
NameTypeAttributesDefaultDescription
format'pcap' | 'pcapng'<optional>
'pcap'The format of the capture file.
Throws:
Throws an error if an unknown format is provided.
Type
Error
Returns:
Returns a read stream of the specified format.
Type: 
PcapInputStream | PcapNGInputStream
Example
const fs = require('node:fs');
const { Pcap } = require('over-the-wire');

// Read packets from a pcapng file
const reader = Pcap.createReadStream({ format: 'pcapng' });
fs.createReadStream('dump.pcapng').pipe(reader);

reader.on('data', (pkt) => {
  console.log('Read packet:', pkt);
});

(inner) createWriteStream(optionsopt) → {PcapOutputStream|PcapNGOutputStream}

Creates a writable stream for network packets to PCAP or PCAPNG formats.
Parameters:
NameTypeAttributesDefaultDescription
optionsObject<optional>
{}Options for creating the write stream.
Properties
NameTypeAttributesDefaultDescription
format'pcap' | 'pcapng'<optional>
'pcap'The format of the capture file.
Throws:
Throws an error if an unknown format is provided.
Type
Error
Returns:
Returns a write stream of the specified format.
Type: 
PcapOutputStream | PcapNGOutputStream
Example
const fs = require('node:fs');
const { Pcap } = require('over-the-wire');

// Save captured packets to a pcapng file
const dump = Pcap.createWriteStream({ format: 'pcapng' });
dump.pipe(fs.createWriteStream('dump.pcapng'));

// Later, when a packet is captured (e.g., from a LiveDevice):
// dump.write(pkt);