Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #76879 > unrolled thread
| Started by | bwatas@gmail.com |
|---|---|
| First post | 2014-08-23 09:24 -0700 |
| Last post | 2014-09-06 11:34 -0700 |
| Articles | 10 — 5 participants |
Back to article view | Back to comp.lang.python
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
| From | bwatas@gmail.com |
|---|---|
| Date | 2014-08-23 09:24 -0700 |
| Subject | ANN: binario - simple work with binary files |
| Message-ID | <33f920ca-16ce-40ce-ab3a-4479beeeae4e@googlegroups.com> |
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 :)
[toc] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-08-23 20:13 -0700 |
| Message-ID | <e920b416-8664-435c-ab9d-f4116e2fa29a@googlegroups.com> |
| In reply to | #76879 |
On Saturday, August 23, 2014 9:54:05 PM UTC+5:30, Алексей Саскевич 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 :) Any advantage of binario over construct? http://construct.readthedocs.org/en/latest/basics.html
[toc] | [prev] | [next] | [standalone]
| From | Алексей Саскевич <bwatas@gmail.com> |
|---|---|
| Date | 2014-08-25 02:58 -0700 |
| Message-ID | <22a04f92-7b77-455c-a080-d72cf5892a25@googlegroups.com> |
| In reply to | #76879 |
Package works directly with files and has similar structure with Java's DataInputStream/DataOutputStream classes. Can construct read/write data from files?
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-08-25 05:33 -0700 |
| Message-ID | <d7f3bce3-294d-451f-aad8-cea9dfed54de@googlegroups.com> |
| In reply to | #76972 |
On Monday, August 25, 2014 3:28:28 PM UTC+5:30, Алексей Саскевич wrote: > Package works directly with files and has similar structure with Java's DataInputStream/DataOutputStream classes. > Can construct read/write data from files? I guess so. See parse_stream: http://construct.readthedocs.org/en/latest/api/core.html
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2014-08-25 14:20 +0100 |
| Message-ID | <mailman.13414.1408972865.18130.python-list@python.org> |
| In reply to | #76972 |
On 25/08/2014 10:58, Алексей Саскевич wrote: > Package works directly with files and has similar structure with Java's DataInputStream/DataOutputStream classes. > Can construct read/write data from files? > Frankly I've no idea and without any context it's impossible to tell. What were you discussing and with whom? -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2014-08-25 18:28 -0700 |
| Message-ID | <23onv9dom4ek64m273bfic5n0c2ldnij8b@4ax.com> |
| In reply to | #76879 |
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.
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-08-25 20:45 -0700 |
| Message-ID | <68d1665b-5369-43f0-8177-352b8949ab20@googlegroups.com> |
| In reply to | #77017 |
On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote:
> bwatas 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.
I thought much the same.
However notice your f.read(). Its type is string.
What if file.dat is a 1GB wav file?
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2014-09-01 17:35 -0700 |
| Message-ID | <h34a0aphuq9tjm5548h2t0c4127a2sjg8o@4ax.com> |
| In reply to | #77022 |
Rustom Mody <rustompmody@gmail.com> wrote:
>On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote:
>> 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.
>
>I thought much the same.
>However notice your f.read(). Its type is string.
>
>What if file.dat is a 1GB wav file?
f.seek(512000)
stuff = struct.unpack( dscrp, f.read(128) )
The point is that files already know how to position themselves.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [next] | [standalone]
| From | Rustom Mody <rustompmody@gmail.com> |
|---|---|
| Date | 2014-09-01 21:35 -0700 |
| Message-ID | <85e4a393-c926-44cd-a0dd-1654cfaa6b4d@googlegroups.com> |
| In reply to | #77424 |
On Tuesday, September 2, 2014 6:05:19 AM UTC+5:30, Tim Roberts wrote:
> Rustom Mody wrote:
> >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote:
> >> 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.
> >I thought much the same.
> >However notice your f.read(). Its type is string.
> >What if file.dat is a 1GB wav file?
> f.seek(512000)
> stuff = struct.unpack( dscrp, f.read(128) )
And what if the struct you are (trying to) unpack is greater or less
than 128 bytes?
> The point is that files already know how to position themselves.
Sure.
But its not enough. One can write a generator that yields one char
at a time. How to feed that to struct.unpack??
[toc] | [prev] | [next] | [standalone]
| From | Tim Roberts <timr@probo.com> |
|---|---|
| Date | 2014-09-06 11:34 -0700 |
| Message-ID | <7ekm0altrkt1q19j0pktm2i3kpk59sgsmb@4ax.com> |
| In reply to | #77432 |
Rustom Mody <rustompmody@gmail.com> wrote:
>On Tuesday, September 2, 2014 6:05:19 AM UTC+5:30, Tim Roberts wrote:
>> Rustom Mody wrote:
>
>> >On Tuesday, August 26, 2014 6:58:42 AM UTC+5:30, Tim Roberts wrote:
>
>> >> 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.
>> >I thought much the same.
>> >However notice your f.read(). Its type is string.
>> >What if file.dat is a 1GB wav file?
>
>> f.seek(512000)
>> stuff = struct.unpack( dscrp, f.read(128) )
>
>And what if the struct you are (trying to) unpack is greater or less
>than 128 bytes?
stuff = struct.unpack( dscrp, f.read(struct.calcsize(dscrp)) )
>But its not enough. One can write a generator that yields one char
>at a time. How to feed that to struct.unpack??
I think you have lost track of the discussion here, because your question
is irrelevant. His binario package couldn't do that, either, since it only
accepts filenames. But at least with struct.unpack, I can suck from the
generator into a string, and feed that string into struct.unpack.
--
Tim Roberts, timr@probo.com
Providenza & Boekelheide, Inc.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.python
csiph-web