From 5b696e2244a57f9893fca90afa0dd664ed58cd86 Mon Sep 17 00:00:00 2001 From: "Zooko O'Whielacronx zooko@zooko.com" Date: Sat, 14 Apr 2007 23:22:45 +0530 Subject: [PATCH] pyfec: add easyfec.Decoder(), which is easier to use than fec.Decoder() darcs-hash:95bf3656157b44e5c7eddfae3430d4db0204ef30 --- pyfec/fec/easyfec.py | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/pyfec/fec/easyfec.py b/pyfec/fec/easyfec.py index de7e8b9..8fc1506 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 + -- 2.45.2