3 # zfec -- a fast C implementation of Reed-Solomon erasure coding with
4 # command-line, C, and Python interfaces
11 from zfec import __version__ as libversion
12 __version__ = libversion
15 if '-V' in sys.argv or '--version' in sys.argv:
16 print "zfec library version: ", libversion
17 print "zunfec command-line tool version: ", __version__
20 parser = argparse.ArgumentParser(description="Decode data from share files.")
22 parser.add_argument('-o', '--outputfile', required=True, help='file to write the resulting data to, or "-" for stdout', type=str, metavar='OUTF')
23 parser.add_argument('sharefiles', nargs='*', help='shares file to read the encoded data from', type=unicode, metavar='SHAREFILE')
24 parser.add_argument('-v', '--verbose', help='print out messages about progress', action='store_true')
25 parser.add_argument('-f', '--force', help='overwrite any file which already in place of the output file', action='store_true')
26 parser.add_argument('-V', '--version', help='print out version number and exit', action='store_true')
27 args = parser.parse_args()
29 if len(args.sharefiles) < 2:
30 print "At least two sharefiles are required."
34 outf = open(args.outputfile, 'wb')
37 flags = os.O_WRONLY|os.O_CREAT|os.O_EXCL | (hasattr(os, 'O_BINARY') and os.O_BINARY)
38 outfd = os.open(args.outputfile, flags)
40 print "There is already a file named %r -- aborting. Use --force to overwrite." % (args.outputfile,)
42 outf = os.fdopen(outfd, "wb")
45 # This sort() actually matters for performance (shares with numbers < k
46 # are much faster to use than the others), as well as being important for
48 args.sharefiles.sort()
49 for fn in args.sharefiles:
50 sharefs.append(open(fn, 'rb'))
52 ret = filefec.decode_from_files(outf, sharefs, args.verbose)
53 except filefec.InsufficientShareFilesError, e:
59 # zfec -- fast forward error correction library with Python interface
61 # Copyright (C) 2007 Allmydata, Inc.
62 # Author: Zooko Wilcox-O'Hearn
64 # This file is part of zfec.
66 # See README.rst for licensing information.