Skip to content

Commit 61fdf87

Browse files
authored
PcapBufferReader to close files (#7)
1 parent a6d3e0f commit 61fdf87

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "PcapTools"
22
uuid = "222fe7e8-3f39-464a-bf97-d9bbb753f246"
33
authors = ["Christian Rorvik <christian.rorvik@gmail.com>"]
4-
version = "1.3.0"
4+
version = "1.4.0"
55

66
[deps]
77
CRC32 = "b4567568-9dcc-467e-9b62-c342d3a501d3"

src/buffer_reader.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,18 @@ mutable struct PcapBufferReader <: PcapReader
2626
end
2727

2828
"""
29-
PcapBufferReader(path::AbstractString)
29+
PcapBufferReader(path::AbstractString; mmap = false)
3030
31-
Memory map file in `path` and create PcapBufferReader over its content.
31+
Read file in `path` to memory and create PcapBufferReader over its content.
32+
33+
If `mmap = true`, file is Mmap.mmap'd to memory instead of reading it.
3234
"""
33-
function PcapBufferReader(path::AbstractString)
34-
io = open(path)
35-
data = Mmap.mmap(io)
35+
function PcapBufferReader(path::AbstractString; mmap = false)
36+
if mmap
37+
data = open(Mmap.mmap, path)
38+
else
39+
data = read(path)
40+
end
3641
PcapBufferReader(data)
3742
end
3843

0 commit comments

Comments
 (0)