The size field (a 32-bit value, encoded using big-endian byte order)
gives the size of the whole chunk, including the 8-byte header.
-Usually a IFF-type file consists of one or more chunks. The proposed
+Usually an IFF-type file consists of one or more chunks. The proposed
usage of the Chunk class defined here is to instantiate an instance at
the start of each chunk and read from the instance until it reaches
the end, after which a new instance can be instantiated. At the end
raise ValueError, "I/O operation on closed file"
return 0
- def seek(self, pos, mode = 0):
+ 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.
raise ValueError, "I/O operation on closed file"
if not self.seekable:
raise IOError, "cannot seek"
- if mode == 1:
+ if whence == 1:
pos = pos + self.size_read
- elif mode == 2:
+ elif whence == 2:
pos = pos + self.chunk_size
if pos < 0 or pos > self.chunksize:
raise RuntimeError
raise ValueError, "I/O operation on closed file"
return self.size_read
- def read(self, n = -1):
- """Read at most n bytes from the chunk.
- If n is omitted or negative, read until the end
+ 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.
"""
raise ValueError, "I/O operation on closed file"
if self.size_read >= self.chunksize:
return ''
- if n < 0:
- n = self.chunksize - self.size_read
- if n > self.chunksize - self.size_read:
- n = self.chunksize - self.size_read
- data = self.file.read(n)
+ if size < 0:
+ size = self.chunksize - self.size_read
+ if size > self.chunksize - self.size_read:
+ size = self.chunksize - self.size_read
+ data = self.file.read(size)
self.size_read = self.size_read + len(data)
if self.size_read == self.chunksize and \
self.align and \