From: Zooko O'Whielacronx Date: Sat, 14 Apr 2007 17:52:45 +0000 (-0700) Subject: pyfec: add easyfec.Decoder(), which is easier to use than fec.Decoder() X-Git-Url: https://git.rkrishnan.org/simplejson/components/something?a=commitdiff_plain;h=89f036c012f9d7a5ea9affa33b6d31736c05e485;p=tahoe-lafs%2Ftahoe-lafs.git pyfec: add easyfec.Decoder(), which is easier to use than fec.Decoder() --- diff --git a/pyfec/fec/easyfec.py b/pyfec/fec/easyfec.py index de7e8b95..8fc15061 100644 --- a/pyfec/fec/easyfec.py +++ b/pyfec/fec/easyfec.py @@ -7,7 +7,6 @@ def div_ceil(n, d): """ return (n/d) + (n%d != 0) - class Encoder(object): def __init__(self, k, m): self.fec = fec.Encoder(k, m) @@ -22,8 +21,17 @@ class Encoder(object): # padding if len(l[-1]) != len(l[0]): l[-1] = l[-1] + ('\x00'*(len(l[0])-len(l[-1]))) - return self.fec.encode(l) - - def decode(self, blocks): - return self.fec.decode(blocks) + res = self.fec.encode(l) + return res +class Decoder(object): + def __init__(self, k, m): + self.fec = fec.Decoder(k, m) + + def decode(self, blocks, sharenums, padlen=0): + blocks = self.fec.decode(blocks, sharenums) + data = ''.join(blocks) + if padlen: + data = data[:-padlen] + return data +