Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77017

Re: ANN: binario - simple work with binary files

From Tim Roberts <timr@probo.com>
Newsgroups comp.lang.python
Subject Re: ANN: binario - simple work with binary files
Date 2014-08-25 18:28 -0700
Organization Providenza & Boekelheide, Inc.
Message-ID <23onv9dom4ek64m273bfic5n0c2ldnij8b@4ax.com> (permalink)
References <33f920ca-16ce-40ce-ab3a-4479beeeae4e@googlegroups.com>

Show all headers | View raw


bwatas@gmail.com wrote:
>
>binario is the Python package that lets an application read/write primitive data types from an underlying input/output file as binary data.
>
>Package on PyPI: https://pypi.python.org/pypi/binario
>Package on GitHub: https://github.com/asaskevich/binario
>Docs: http://binarios-docs.readthedocs.org/en/latest/
>
>Package still in Alpha, and I need some help with testing, new features and docs :)

I hope you will accept constructive criticism.

The documentation says it lets an application read/write binary data from
an "underlying input/output stream".  That's not really accurate.  "Stream"
implies something very general, but your constructors will only accept
filenames.  Your code ONLY works with files.  If I have a stream of data in
memory, or an already open file, your code can't be used.

This is why packages like "struct" (which is basically a more compact
version of what you are doing) read from a string or a buffer, and leave
the file-like behavior to things that already know how to behave like
files.

Compare your sample code:

  >>> import binario
  >>> r = binario.Reader("file.dat")
  >>> r.read_short()
  2014
  >>> r.read_bool()
  True
  >>> r.read_float()
  3.1415
  >>> r.read_string()
  "Hello, world!"
  >>> r.read(5)
  b'\x80\x14\n\xff\x00'

To the equivalent code with struct:

  import struct

  dscrp = "H?fs5B"

  f = open('file.dat')
  stuff = struct.unpack( dscrp, f.read() )

  print stuff

In both cases, you have to KNOW the format of the data beforehand.  If you
do a read_short where you happen to have written a float, disaster ensues.

I don't really see that you've added very much.
-- 
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

ANN: binario - simple work with binary files bwatas@gmail.com - 2014-08-23 09:24 -0700
  Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-08-23 20:13 -0700
  Re: ANN: binario - simple work with binary files Алексей Саскевич <bwatas@gmail.com> - 2014-08-25 02:58 -0700
    Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-08-25 05:33 -0700
    Re: ANN: binario - simple work with binary files Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-08-25 14:20 +0100
  Re: ANN: binario - simple work with binary files Tim Roberts <timr@probo.com> - 2014-08-25 18:28 -0700
    Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-08-25 20:45 -0700
      Re: ANN: binario - simple work with binary files Tim Roberts <timr@probo.com> - 2014-09-01 17:35 -0700
        Re: ANN: binario - simple work with binary files Rustom Mody <rustompmody@gmail.com> - 2014-09-01 21:35 -0700
          Re: ANN: binario - simple work with binary files Tim Roberts <timr@probo.com> - 2014-09-06 11:34 -0700

csiph-web