digraph inheritance98a91698ac { rankdir=LR; ratio=compress; fontsize=14; size="6.0, 8.0"; "Unpacker" [shape=ellipse,URL="#nibabel.nicom.structreader.Unpacker",fontname=Vera Sans, DejaVu Sans, Liberation Sans, Arial, Helvetica, sans,fontsize=14,color=dodgerblue1,style=filled,height=0.75]; }
Class to unpack values from buffer object
The buffer object is usually a string. Caches compiled struct format strings so that repeated unpacking with the same format string should be faster than using struct.unpack directly.
Examples
>>> a = '1234567890'
>>> upk = Unpacker(a)
>>> upk.unpack('2s')
('12',)
>>> upk.unpack('2s')
('34',)
>>> upk.ptr
4
>>> upk.read(3)
'567'
>>> upk.ptr
7
Methods
read | |
unpack |
Initialize unpacker
Parameters : | buf : buffer
ptr : int, optional
endian : None or str, optional
|
---|
Methods
read | |
unpack |
Return byte string of length n_bytes at current position
Returns sub-string from self.buf and updates self.ptr to the position after the read data.
Parameters : | n_bytes : int, optional
|
---|---|
Returns : | s : byte string |
Unpack values from contained buffer
Unpacks values from self.buf and updates self.ptr to the position after the read data.
Parameters : | fmt : str
|
---|---|
Returns : | values : tuple
|