packetsize = 4 size = 32 mode = HSRCMode.SCHDULE enc_points = numpy.ndarray(dtype=numpy.uint32, shape=(n,)) dec_points = numpy.ndarray(dtype=numpy.uint32, shape=(k,)) raw_data = [numpy.ndarray(shape=(size,), dtype=numpy.uint8) for i in xrange(k)] for i,buff in enumerate(raw_data): buff.fill(i) encoded_data = [numpy.zeros(size, dtype=numpy.uint8) for i in xrange(n)] for i,p in enumerate([1,2,3,4,5,6,7]): enc_points[i] = p encoder = HSRC(k, enc_points, w=w, packetsize=packetsize, mode=mode) print "Encoding matrix:" encoder.print_matrix() print "Raw data:" for i,d in enumerate(raw_data): print i,d encoder.encode(raw_data, encoded_data) print "Encoded data:" for i,d in enumerate(encoded_data): print i,enc_points[i],d print "Repairing 0 from 2 and 1:" enc_points[0] = enc_points[1]^enc_points[2]
file_size = os.path.getsize(file_name) survived = [] inputfiles = [] for i in xrange(n): name = file_name+"_%d"%i if os.path.exists(name): inputfiles.append(io.open(file_name+"_%d"%i,'rb')) survived.append(i) outputfile = io.open(file_name+"_decoded", 'wb') for i,p in enumerate(survived): dec_points[i] = p+1 print dec_points decoder = HSRC(k, dec_points, w=w, packetsize=packetsize, mode=mode, decoder=True) readblock = k*buffsize to_read = file_size while to_read>0: for i,inputf in enumerate(inputfiles): inputf.readinto(encoded_data[i]) decoder.decode(encoded_data, raw_data) if to_read>=readblock: for rd in raw_data: outputfile.write(rd) to_read -= readblock else: data = to_read for rd in raw_data: outputfile.write(buffer(rd,0,to_read))
k = 3 n = 7 w = 32 packetsize = 128 buffsize = w*packetsize mode = HSRCMode.SCHDULE enc_points = numpy.ndarray(dtype=numpy.uint32, shape=(n,)) for i,p in enumerate([1,2,3,4,5,6,7]): enc_points[i] = p raw_data = [numpy.ndarray(shape=(buffsize,), dtype=numpy.uint8) for i in xrange(k)] encoded_data = [numpy.zeros(buffsize, dtype=numpy.uint8) for i in xrange(n)] encoder = HSRC(k, enc_points, w=w, packetsize=packetsize, mode=mode) file_name = sys.argv[1] file_size = os.path.getsize(file_name) inputfile = io.open(file_name, 'rb') outputfiles = [io.open(file_name+"_%d"%i,'wb') for i in xrange(n)] read_block = k*buffsize to_read = file_size while to_read>0: for i in xrange(k): data_read = inputfile.readinto(raw_data[i]) to_read -= data_read encoder.encode(raw_data, encoded_data) for ed,of in itertools.izip(encoded_data, outputfiles):