Skip to content

Commit

Permalink
Merge branch 'release-v1.6.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
cartoonist committed Apr 20, 2023
2 parents 2d7709a + 5d50933 commit 799ca72
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ Refer to the C++ [stream library](https://github.com/vgteam/stream) for more
details.

---

**NOTE**

**@vg users:** The new version of stream library, now as a part of
[libvgio](https://github.com/vgteam/libvgio), writes a header at the start of
[libvgio](https://github.com/vgteam/libvgio), writes a header tag at the start of
the stream depending on the output format. For example, headers like `b'GAM'`
or `b'VG'` can be found before the actual protobuf messages in GAM and VG files
repectively. In this case, you should provide the expected value using `header`
keyword argument; e.g.
`stream.parse('file.gam', vg_pb2.Alignment, header=b'GAM')`
`stream.parse('file.gam', vg_pb2.Alignment, header=b'GAM', persistent_header=True)`
for GAM files (since version v1.6.2).

---
Expand Down
2 changes: 1 addition & 1 deletion stream/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
__license__ = 'MIT'

# Release
__version__ = '1.6.3'
__version__ = '1.6.4'
__status__ = DS_STABLE

# PyPI-related information
Expand Down
12 changes: 9 additions & 3 deletions stream/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ def __init__(self, filename=None, mode='rb', fileobj=None, **kwargs):
gzip (bool): Whether or not to use gzip compression on the given
file. (default is True)
header (bytes): the header which is expected to read or write.
persistent_header (bool): whether headers occur before any data
blob. (default is False)
serialize (function): serialising an input object to byte string.
If `None`, input objects are assumed to be protobuf messages.
"""
Expand All @@ -150,6 +152,7 @@ def __init__(self, filename=None, mode='rb', fileobj=None, **kwargs):
else:
self._fd = fileobj
self._header = kwargs.pop('header', b'')
self._pers_header = kwargs.pop('persistent_header', False)
if not mode.startswith('r'):
self._buffer_size = kwargs.pop('buffer_size', 0)
self._serialize = kwargs.pop('serialize', self.serialize_to_string)
Expand Down Expand Up @@ -269,7 +272,8 @@ def __next__(self):
val = self._next()
if self._header:
if val == self._header:
self._header = b''
if not self._pers_header:
self._header = b''
return self._next()
raise RuntimeError("mismatch header (fetched {v})".format(v=val))
return val
Expand All @@ -281,7 +285,8 @@ async def __anext__(self):
val = await self._anext()
if self._header:
if val == self._header:
self._header = b''
if not self._pers_header:
self._header = b''
return await self._anext()
raise RuntimeError("mismatch header (fetched {v})".format(v=val))
return val
Expand Down Expand Up @@ -349,7 +354,8 @@ def _write_header(self):
assert self._header
encodeVarint(self._fd.write, len(self._header), True)
self._fd.write(self._header)
self._header = b''
if not self._pers_header:
self._header = b''

def flush(self):
"""Write down buffer to the file."""
Expand Down

0 comments on commit 799ca72

Please sign in to comment.