Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
Chunk Class Reference

Public Member Functions

def __init__
 
def getname
 
def getsize
 
def close
 
def isatty
 
def seek
 
def tell
 
def read
 
def skip
 

Data Fields

 closed
 
 align
 
 file
 
 chunkname
 
 chunksize
 
 size_read
 
 offset
 
 seekable
 

Detailed Description

Definition at line 51 of file chunk.py.

Constructor & Destructor Documentation

def __init__ (   self,
  file,
  align = 1,
  bigendian = 1,
  inclheader = 0 
)

Definition at line 52 of file chunk.py.

52 
53  def __init__(self, file, align = 1, bigendian = 1, inclheader = 0):
54  import struct
55  self.closed = 0
56  self.align = align # whether to align to word (2-byte) boundaries
57  if bigendian:
58  strflag = '>'
59  else:
60  strflag = '<'
61  self.file = file
62  self.chunkname = file.read(4)
63  if len(self.chunkname) < 4:
64  raise EOFError
65  try:
66  self.chunksize = struct.unpack(strflag+'l', file.read(4))[0]
67  except struct.error:
68  raise EOFError
69  if inclheader:
70  self.chunksize = self.chunksize - 8 # subtract header
71  self.size_read = 0
72  try:
73  self.offset = self.file.tell()
74  except (AttributeError, IOError):
75  self.seekable = 0
76  else:
77  self.seekable = 1

Member Function Documentation

def close (   self)

Definition at line 86 of file chunk.py.

References Chunk.closed, and Chunk.skip().

86 
87  def close(self):
88  if not self.closed:
89  self.skip()
90  self.closed = 1
def getname (   self)
Return the name (ID) of the current chunk.

Definition at line 78 of file chunk.py.

References Chunk.chunkname.

78 
79  def getname(self):
80  """Return the name (ID) of the current chunk."""
81  return self.chunkname
def getsize (   self)
Return the size of the current chunk.

Definition at line 82 of file chunk.py.

References Chunk.chunksize.

82 
83  def getsize(self):
84  """Return the size of the current chunk."""
85  return self.chunksize
def isatty (   self)

Definition at line 91 of file chunk.py.

References Chunk.closed.

91 
92  def isatty(self):
93  if self.closed:
94  raise ValueError, "I/O operation on closed file"
95  return 0
def read (   self,
  size = -1 
)
Read at most size bytes from the chunk.
If size is omitted or negative, read until the end
of the chunk.

Definition at line 120 of file chunk.py.

References Chunk.align, Chunk.chunksize, Chunk.closed, and Chunk.size_read.

121  def read(self, size = -1):
122  """Read at most size bytes from the chunk.
123  If size is omitted or negative, read until the end
124  of the chunk.
125  """
126 
127  if self.closed:
128  raise ValueError, "I/O operation on closed file"
129  if self.size_read >= self.chunksize:
130  return ''
131  if size < 0:
132  size = self.chunksize - self.size_read
133  if size > self.chunksize - self.size_read:
134  size = self.chunksize - self.size_read
135  data = self.file.read(size)
136  self.size_read = self.size_read + len(data)
137  if self.size_read == self.chunksize and \
138  self.align and \
139  (self.chunksize & 1):
140  dummy = self.file.read(1)
141  self.size_read = self.size_read + len(dummy)
142  return data
def seek (   self,
  pos,
  whence = 0 
)
Seek to specified position into the chunk.
Default position is 0 (start of chunk).
If the file is not seekable, this will result in an error.

Definition at line 96 of file chunk.py.

References Chunk.chunksize, Chunk.closed, Chunk.offset, Chunk.seekable, and Chunk.size_read.

96 
97  def seek(self, pos, whence = 0):
98  """Seek to specified position into the chunk.
99  Default position is 0 (start of chunk).
100  If the file is not seekable, this will result in an error.
101  """
102 
103  if self.closed:
104  raise ValueError, "I/O operation on closed file"
105  if not self.seekable:
106  raise IOError, "cannot seek"
107  if whence == 1:
108  pos = pos + self.size_read
109  elif whence == 2:
110  pos = pos + self.chunksize
111  if pos < 0 or pos > self.chunksize:
112  raise RuntimeError
113  self.file.seek(self.offset + pos, 0)
114  self.size_read = pos
def skip (   self)
Skip the rest of the chunk.
If you are not interested in the contents of the chunk,
this method should be called so that the file points to
the start of the next chunk.

Definition at line 143 of file chunk.py.

References Chunk.align, Chunk.chunksize, Chunk.closed, sre_parse.min, openrsrc.read(), Chunk.read(), _Hqxdecoderengine.read(), _Rledecoderengine.read(), HexBin.read(), file_wrapper.read, Unpickler.read, addbase.read, Chunk.seekable, and Chunk.size_read.

144  def skip(self):
145  """Skip the rest of the chunk.
146  If you are not interested in the contents of the chunk,
147  this method should be called so that the file points to
148  the start of the next chunk.
149  """
150 
151  if self.closed:
152  raise ValueError, "I/O operation on closed file"
153  if self.seekable:
154  try:
155  n = self.chunksize - self.size_read
156  # maybe fix alignment
157  if self.align and (self.chunksize & 1):
158  n = n + 1
159  self.file.seek(n, 1)
160  self.size_read = self.size_read + n
161  return
162  except IOError:
163  pass
164  while self.size_read < self.chunksize:
165  n = min(8192, self.chunksize - self.size_read)
166  dummy = self.read(n)
167  if not dummy:
168  raise EOFError
def tell (   self)

Definition at line 115 of file chunk.py.

References Chunk.closed, and Chunk.size_read.

116  def tell(self):
117  if self.closed:
118  raise ValueError, "I/O operation on closed file"
119  return self.size_read

Field Documentation

align

Definition at line 55 of file chunk.py.

chunkname

Definition at line 61 of file chunk.py.

chunksize

Definition at line 65 of file chunk.py.

closed

Definition at line 54 of file chunk.py.

file

Definition at line 60 of file chunk.py.

offset

Definition at line 72 of file chunk.py.

seekable

Definition at line 74 of file chunk.py.

size_read

Definition at line 70 of file chunk.py.


The documentation for this class was generated from the following file: