PcapFileEx.Stream (pcap_file_ex v0.1.5)
View SourceStream protocol implementation for lazy packet reading.
Summary
Functions
Creates a lazy stream of packets from an already opened reader.
Creates a lazy stream of packets from a PCAP file.
Functions
@spec from_reader(PcapFileEx.Pcap.t() | PcapFileEx.PcapNg.t()) :: Enumerable.t()
Creates a lazy stream of packets from an already opened reader.
This does NOT automatically close the reader when done. Works with both PCAP and PCAPNG readers.
Examples
{:ok, reader} = PcapFileEx.Pcap.open("capture.pcap")
PcapFileEx.Stream.from_reader(reader)
|> Enum.take(10)
PcapFileEx.Pcap.close(reader)
{:ok, reader} = PcapFileEx.PcapNg.open("capture.pcapng")
PcapFileEx.Stream.from_reader(reader)
|> Enum.take(10)
PcapFileEx.PcapNg.close(reader)
@spec packets(Path.t()) :: Enumerable.t()
Creates a lazy stream of packets from a PCAP file.
The stream automatically handles opening and closing the file.
Examples
PcapFileEx.Stream.packets("capture.pcap")
|> Stream.filter(fn packet -> byte_size(packet.data) > 1000 end)
|> Enum.take(10)