kutsurak / python-bitstring

Automatically exported from code.google.com/p/python-bitstring
0 stars 0 forks source link

readto method #105

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
A mixture between a find and a read, the method looks for the next occurence of 
a bitstring and reads up to that point:

def readto(self, bs, bytealigned=False):
    ...

If the bitstring isn't found then a ReadError is thrown.

For symmetry we also need a peekto() method.

Perhaps also consider a readnext/peeknext method, which does the same except 
will also read the bitstring being searched for.

>>> a = BitStream('0xabcd00ab')
>>> a.readnext('0x00', True)
BitStream('0xabcd00')

Original issue reported on code.google.com by dr.scott...@gmail.com on 27 Feb 2011 at 3:54

GoogleCodeExporter commented 9 years ago
worth noting that with this name a user might try something like

    s.readto(1000)

and expect it to read up to bit 1000, rather than up to the first occurrence of 
1000 zero bits!

Perhaps we should disallow integers to avoid the problem. Or rename the method 
(but I can't think of anything better).

Original comment by dr.scott...@gmail.com on 29 May 2011 at 4:33

GoogleCodeExporter commented 9 years ago

Original comment by dr.scott...@gmail.com on 18 Jun 2011 at 6:20

GoogleCodeExporter commented 9 years ago
The method plus unit tests was added, but commented out for the 2.2 release as 
I wasn't convinced it was useful and general enough for inclusion. Will 
reconsider for next release?

Original comment by dr.scott...@gmail.com on 18 Jun 2011 at 6:26

GoogleCodeExporter commented 9 years ago

Original comment by dr.scott...@gmail.com on 17 Aug 2011 at 6:36

GoogleCodeExporter commented 9 years ago
Done for version 3.0.

Original comment by dr.scott...@gmail.com on 20 Nov 2011 at 9:15