Skip to content

Commit

Permalink
Merge pull request #1 from BravelyPeculiar/master
Browse files Browse the repository at this point in the history
Added get_bytes() to Writer for convenience
  • Loading branch information
leoetlino authored Apr 7, 2019
2 parents e528ec9 + 5f9adee commit 508c590
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions byml/byml.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# Licensed under GPLv2+
from enum import IntEnum
from sortedcontainers import SortedDict # type: ignore
import io
import struct
import typing

Expand Down Expand Up @@ -235,6 +236,11 @@ def __init__(self, data: typing.Union[dict, list], be=False, version=2) -> None:
self._sort_string_table(self._hash_key_table)
self._sort_string_table(self._string_table)

def get_bytes(self):
stream = io.BytesIO()
self.write(stream)
return stream.getvalue()

def write(self, stream: typing.BinaryIO) -> None:
# Header
stream.write(b'BY' if self._be else b'YB')
Expand Down

0 comments on commit 508c590

Please sign in to comment.