1.1 --- a/iixr/files.py Tue Jan 25 00:36:31 2011 +0100
1.2 +++ b/iixr/files.py Tue Jan 25 01:55:43 2011 +0100
1.3 @@ -3,7 +3,7 @@
1.4 """
1.5 Generic file access.
1.6
1.7 -Copyright (C) 2009, 2010 Paul Boddie <paul@boddie.org.uk>
1.8 +Copyright (C) 2009, 2010, 2011 Paul Boddie <paul@boddie.org.uk>
1.9
1.10 This program is free software; you can redistribute it and/or modify it under
1.11 the terms of the GNU General Public License as published by the Free Software
1.12 @@ -18,7 +18,7 @@
1.13 with this program. If not, see <http://www.gnu.org/licenses/>.
1.14 """
1.15
1.16 -from iixr.data import vint, vint_to_array
1.17 +from iixr.data import vint, vint_to_array, vint_from_array
1.18 from array import array
1.19 import zlib
1.20
1.21 @@ -76,6 +76,15 @@
1.22
1.23 self.f.write(vint(number))
1.24
1.25 + def write_numbers(self, numbers):
1.26 +
1.27 + "Write 'numbers' to the file using a variable length encoding."
1.28 +
1.29 + output = array('B')
1.30 + for number in numbers:
1.31 + vint_to_array(number, output)
1.32 + output.tofile(self.f)
1.33 +
1.34 def write_string(self, s, compress=0):
1.35
1.36 """
1.37 @@ -152,7 +161,7 @@
1.38 while csd & 128:
1.39 fromfile(f, 1)
1.40 csd = a[-1]
1.41 - return sum([((csd & 127) << (number * 7)) for (number, csd) in enumerate(a)])
1.42 + return vint_from_array(a)
1.43
1.44 def read_string(self, decompress=0):
1.45
1.46 @@ -184,16 +193,21 @@
1.47
1.48 def read_sequence(self, last, size, monotonic=1):
1.49 if size:
1.50 - expect_delta = 1
1.51 value = []
1.52 - for v in last:
1.53 - v_in = self.read_number()
1.54 - if monotonic or expect_delta:
1.55 + if monotonic:
1.56 + for v in last:
1.57 + v_in = self.read_number()
1.58 value.append(v + v_in)
1.59 - if expect_delta and v_in != 0:
1.60 - expect_delta = 0
1.61 - else:
1.62 - value.append(v_in - 1)
1.63 + else:
1.64 + expect_delta = 1
1.65 + for v in last:
1.66 + v_in = self.read_number()
1.67 + if expect_delta:
1.68 + value.append(v + v_in)
1.69 + if v_in != 0:
1.70 + expect_delta = 0
1.71 + else:
1.72 + value.append(v_in - 1)
1.73 return tuple(value)
1.74 else:
1.75 return last + self.read_number()