Skip to content

Commit

Permalink
earthkit.regrid.utils.Stream write functionality (for most data types)
Browse files Browse the repository at this point in the history
  • Loading branch information
pmaciel committed Jan 14, 2025
1 parent e3c3ca1 commit 730b539
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/earthkit/regrid/utils/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,10 @@ def __init__(self, stream):
def _read(self, n):
return self.stream.read(n)

def _write(self, n, nbytes=None):
assert not nbytes or nbytes == len(n)
return self.stream.write(n)

def read_tag(self, expected_tag):
tag = self._read(1)
tag = ord(tag)
Expand Down Expand Up @@ -131,7 +135,9 @@ def write_long(self, n):

def write_double(self, n):
self.write_tag(TAG_DOUBLE)
raise RuntimeError("write_doble")
x, y = unpack("!II", pack("!d", n))
self.stream.write(pack("!L", y))
self.stream.write(pack("!L", x))

def write_unsigned_long(self, n):
self.write_tag(TAG_UNSIGNED_LONG)
Expand Down

0 comments on commit 730b539

Please sign in to comment.