xbrianh / xbgzip

Fast streams for block gzip files.
MIT License
6 stars 2 forks source link

test error #7

Closed zpliu1126 closed 1 year ago

zpliu1126 commented 1 year ago

Hi developer~

I test the bgzip in jupyter,and it failed.

with open("my_bgzipped_file.gz", "wb") as raw:
    with bgzip.BGZipWriter(raw) as fh:
        fh.write("11")

error log

TypeError                                 Traceback (most recent call last)
Cell In [22], line 3
      1 with open("my_bgzipped_file.gz", "wb") as raw:
      2     with bgzip.BGZipWriter(raw) as fh:
----> 3         fh.write("11")

File ~/.local/lib/python3.9/site-packages/bgzip/__init__.py:216, in BGZipWriter.write(self, data)
    [215](file:///public/home/zpliu/.local/lib/python3.9/site-packages/bgzip/__init__.py?line=214) def write(self, data):
--> [216](file:///public/home/zpliu/.local/lib/python3.9/site-packages/bgzip/__init__.py?line=215)     self._input_buffer.extend(data)
    [217](file:///public/home/zpliu/.local/lib/python3.9/site-packages/bgzip/__init__.py?line=216)     if len(self._input_buffer) > self.batch_size * bgzip_utils.block_data_inflated_size:
    [218](file:///public/home/zpliu/.local/lib/python3.9/site-packages/bgzip/__init__.py?line=217)         self._compress()

TypeError: 'str' object cannot be interpreted as an integer
dawe commented 1 year ago

the writer expects bytes. If you have strings you can easily convert them into bytearrays and pass to it:

with open("my_bgzipped_file.gz", "wb") as raw:
    with bgzip.BGZipWriter(raw) as fh:
        fh.write(b"11") #or bytes('11', encoding='ascii')