detectPcapMagic(buffer: Uint8Array): PcapMagicInfo | null
Inspects the first four bytes of a buffer to identify the pcap magic.
Returns the decoded PcapMagicInfo, or null if the bytes do not
match any of the four known pcap magic values. Useful when the caller
receives an arbitrary buffer and needs to pick the correct
pcapGlobalHeader factory before decoding.
Detect a little-endian microsecond capture
Detect a little-endian microsecond capture
import { assertEquals } from "@std/assert"; import { detectPcapMagic } from "@binstruct/pcap"; const buffer = new Uint8Array([0xd4, 0xc3, 0xb2, 0xa1]); assertEquals(detectPcapMagic(buffer), { endianness: "le", nanos: false });
buffer: Uint8Array
Buffer whose first four bytes hold the magic number.
PcapMagicInfo | null
Endianness and timestamp resolution implied by the magic, or
null if no recognised magic is present.