Skip to content

Commit 63e94f3

Browse files
committed
feature: add option to suppress path extraction (for faster execution)
1 parent b0b95e3 commit 63e94f3

4 files changed

Lines changed: 269 additions & 141 deletions

File tree

benchmarks/streamson-bench

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def streamson_generic(
4444

4545
with (pathlib.Path(dst_path).open("w") if dst_path else nullcontext()) as outputf:
4646
with pathlib.Path(src_path).open("rb") as inputf:
47-
for path, data in extract_function(reader(inputf), matcher, convert):
47+
for path, data in extract_function(reader(inputf), matcher, convert, require_path=False):
4848
count += 1
4949
if outputf:
5050
outputf.write(f"{data}\n")
@@ -58,7 +58,7 @@ def streamson_fd(src_path: str, dst_path: typing.Optional[str] = None):
5858
count = 0
5959
with (pathlib.Path(dst_path).open("w") if dst_path else nullcontext()) as outputf:
6060
with pathlib.Path(src_path).open("rb") as inputf:
61-
for path, data in extract_fd(inputf, matcher, buffer_size=BUFF_SIZE):
61+
for path, data in extract_fd(inputf, matcher, buffer_size=BUFF_SIZE, require_path=False):
6262
count += 1
6363
if outputf:
6464
outputf.write(f"{data!r}\n")

streamson/__init__.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ def extract_iter(
5151
input_gen: typing.Generator[bytes, None, None],
5252
matcher: Matcher,
5353
convert: typing.Callable[[str], typing.Any] = lambda x: x,
54+
require_path: bool = True,
5455
) -> typing.Generator[typing.Tuple[str, typing.Any], None, None]:
5556
"""Extracts json specified by given list of simple matches
5657
:param: input_gen: input generator
5758
:param: matcher: used matcher
5859
:param: convert: function used to convert raw data
60+
:param: require_path: is path required in output stream
5961
6062
:yields: path and converted data
6163
"""
62-
streamson = _Streamson(matcher.inner)
64+
streamson = _Streamson(matcher.inner, require_path)
6365
for item in input_gen:
6466
streamson.feed(item)
6567
res = streamson.pop()
@@ -74,16 +76,18 @@ def extract_fd(
7476
matcher: Matcher,
7577
buffer_size: int = 1024 * 1024,
7678
convert: typing.Callable[[str], typing.Any] = lambda x: x,
79+
require_path: bool = True,
7780
) -> typing.Generator[typing.Tuple[str, typing.Any], None, None]:
7881
"""Extracts json specified by given list of simple matches
7982
:param: input_fd: input fd
8083
:param: buffer_size: how many bytes can be read from a file at once
8184
:param: matcher: used matcher
8285
:param: convert: function used to convert raw data
86+
:param: require_path: is path required in output stream
8387
8488
:yields: path and converted data
8589
"""
86-
streamson = _Streamson(matcher.inner)
90+
streamson = _Streamson(matcher.inner, require_path)
8791
input_data = input_fd.read(buffer_size)
8892

8993
while input_data:

0 commit comments

Comments
 (0)